Skip to content

fix(tui): apply theme only on confirm in theme list - #62498

Open
ColonelToad wants to merge 1 commit into
anomalyco:devfrom
ColonelToad:theme-list-confirm
Open

ColonelToad wants to merge 1 commit into
anomalyco:devfrom
ColonelToad:theme-list-confirm

Conversation

@ColonelToad

@ColonelToad ColonelToad commented Nov 7, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #56147

Type of change

  • Bug fix

What does this PR do?

The theme dialog called themes.set() from onMove and onFilter, and restored the original theme from onCleanup when the dialog closed without confirmation. Browsing the list therefore applied the theme on every arrow key and every filter keystroke, so the whole TUI changed appearance while the user was only looking. The reporter's thread describes the same behavior and asks for the model, agent and variant dialog behavior instead: highlight while navigating, apply on confirmation.

This drops the live preview. DialogSelect already tracks its own highlighted row and accepts current, so the dialog now starts on the active theme, moves the highlight without calling themes.set(), and applies the theme only in onSelect. Esc closes without writing; Enter applies the highlighted theme. The onCleanup restore is removed because there is no longer a live change to roll back.

The dialog keeps onClose, so the settings entry point still returns to the settings list instead of closing every dialog.

What this does not change

DialogSelect, the theme provider and palette handling, and the external-config hot reload in #37423. It also does not add an optional preview switch: the preview is removed rather than made configurable, which is what the reporter asked for and what the maintainer restated in the thread.

How did you verify your code works?

New packages/tui/test/component/dialog-theme-list.test.tsx renders the dialog and asserts four things: arrow-down leaves themes.selected unchanged, typing a filter leaves it unchanged, Esc closes the dialog and leaves it unchanged, and moving to another row then pressing Enter applies that theme.

On dev's component the test fails at the first assertion: the selected theme changes from opencode to orng as soon as the arrow key is pressed. With this branch's component the same test passes.

On Debian 13/WSL2 with Bun 1.4.4:

  • cd packages/tui && bun test test/component/dialog-theme-list.test.tsx → 1 pass, 0 fail (4 expects)
  • bun run check → 32/32 tasks successful

Limitations

The test drives the dialog through the TUI test renderer and the fixture theme source, not a real terminal session, so it checks the dialog's state calls rather than the rendered palette. The settings entry point that passes onClose is not exercised by the test; it uses the same onSelect path.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" role="img" aria-label="Moving through the theme list only highlights a row; pressing Enter applies the highlighted theme">
  <style>
    text {
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
      font-size: 7.5px;
      fill: currentColor;
    }
    .muted { opacity: 0.55; }
    .faint { opacity: 0.35; }
    .highlight { animation: move 7s ease-in-out infinite; }
    .before { animation: before 7s ease-in-out infinite; }
    .after { opacity: 0; animation: after 7s ease-in-out infinite; }
    @keyframes move {
      0%, 12% { transform: translateY(0); }
      22%, 40% { transform: translateY(10px); }
      50%, 62% { transform: translateY(20px); }
      74%, 100% { transform: translateY(10px); }
    }
    @keyframes before {
      0%, 68% { opacity: 1; }
      76%, 100% { opacity: 0; }
    }
    @keyframes after {
      0%, 68% { opacity: 0; }
      76%, 100% { opacity: 1; }
    }
    @media (prefers-reduced-motion: reduce) {
      .highlight, .before, .after { animation: none; }
      .before { opacity: 0; }
      .after { opacity: 1; }
    }
  </style>
  <rect x="1" y="1" width="238" height="70" rx="5" fill="none" stroke="currentColor" stroke-opacity="0.25"/>
  <text class="muted" x="10" y="14">Themes</text>
  <text class="faint" x="230" y="14" text-anchor="end">Esc</text>
  <rect class="highlight" x="6" y="20" width="228" height="10" rx="2" fill="currentColor" opacity="0.12"/>
  <text x="12" y="28">Dark</text>
  <text x="12" y="38">Light</text>
  <text x="12" y="48">System</text>
  <text class="muted" x="152" y="28">theme</text>
  <text class="before" x="190" y="28">Dark</text>
  <text class="after" x="190" y="28">Light</text>
  <text class="faint" x="12" y="62">move highlights · Enter applies</text>
</svg>

AI assistance

I used AI assistance to investigate this issue and draft the change. I reviewed the diff, ran the test and checks above, and am accountable for the code in this PR.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #61598

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as described. I drove /themes in the TUI from source on both branches: on the base, pressing the down arrow applies each highlighted theme to the whole UI right away; with this PR only the highlight moves and the palette stays the same until you press Enter. The new test fails on the base and passes here. In the TUI package, tsc shows the same errors on the base and on this PR, none of them in the changed files. The public API is unchanged.

The change is sound. DialogSelect already starts the highlight on current and handles filtering by itself, and both callers keep working (app.tsx, and Settings through onClose). No concerns.

Related: #61598

Before

After

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: dialog-theme-list changes theme live on navigate/filter

1 participant