Skip to content

fix(tui): Esc clears a kept list filter before exiting - #2693

Merged
cliffhall merged 2 commits into
v2/mainfrom
v2/fix/2647-tui-esc-clears-kept-filter
Oct 12, 2026
Merged

cliffhall merged 2 commits into
v2/mainfrom
v2/fix/2647-tui-esc-clears-kept-filter

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #2647

Problem

In a TUI list filter (#2430), Esc while typing cleared the filter. But once the filter was kept with Enter, the next Esc went to App's exit accelerator and quit the whole TUI. That's a lossy result for one keystroke when the user only wanted to undo the filter.

Change

A kept filter now claims Esc while its list has the keyboard. The first Esc clears it and the second exits.

  • useListFilter: when not editing and the query is non-empty, Esc clears it and is consumed. The hook reports the claim through a new onEscapeClaimChange option. Like onEditingChange, it's an effect with a cleanup, so the claim is withdrawn on every way it can end: the query is cleared, the pane loses focus, a modal opens, or the tab unmounts. That means App can never be left unable to exit.
  • Tools / Resources / Prompts / Skills tabs pass the report through as onFilterEscapeClaimChange.
  • App skips exit() on Esc while the claim is held. Only Esc stands down. A filter is kept so that the other accelerators work on the narrowed list, so they stay live. (Editing still mutes everything, as before.)
  • ? help overlay (TUI has no in-app shortcut/keybinding help screen #2436), as the issue asks: the global row now reads Exit (Esc closes a dialog or clears a kept filter first). The / row's existing Filter the list (Enter keeps it, Esc clears it) is now true of a kept filter as well, so it stays as is. A longer wording truncated in an 80-column overlay (f16ef79).
  • Filter bar hint: a kept filter on a focused list now shows (/ edit · Esc clear). An unfocused list keeps (/ to edit), because Esc doesn't clear it there.

Scope note: the claim exists only while the list pane has the keyboard, the same condition under which / works. If you Tab away to the details pane, the filter stays kept and Esc exits as before.

Tests

  • useListFilter.test.tsx: Esc clears a kept filter and withdraws the claim, and the second Esc is left unconsumed for the app. Editing never claims. The claim is withdrawn, and Esc no longer clears, when the list loses the keyboard.
  • App.test.tsx: the issue's repro (t, Tab, /dpt, Enter, Esc) clears the filter (Tools (1/2) → Tools (2)) and the app still answers d. I checked that this test fails with App's guard removed.
  • ListFilterBar.test.tsx / ToolsTab.test.tsx: the focused kept-filter hint.

npm run local:gate passed on 4fdf2d6. f16ef79 only reverts one help string to its pre-PR text. For that commit I re-ran the keybindings and HelpOverlay suites and prettier --check, but not the full gate.

Screenshots (text captures)

These are ANSI-stripped Ink frames of the real App (80 columns), produced by the same renderTui helper the tests use, as on #2592. The 80-column test terminal truncates the hint in the narrow list pane. The full text is (/ edit · Esc clear).

Before: after t, Tab, /, dpt, Enter, then Esc, the TUI exited (exit 0). There's no frame to show.

After: filter kept (/dpt, Enter):

                       │                     │
                       │ Tools (1/2)         │ dpt-tool         [Enter to Test]
                       │                     │
                       │ /dpt (/ edit · Esc… │ D
                       │ ▶ dpt-tool          │
                       │                     │ Input Schema:

After: first Esc clears the filter, and the TUI is still running:

                       │                     │
                       │ Tools (2)           │ alpha            [Enter to Test]
                       │                     │
                       │ / to filter         │ Tool desc line1
                       │ ▶ alpha             │ line2
                       │   dpt-tool          │

? help overlay, the changed global row:

 │ Esc / Ctrl+C     Exit (Esc closes a dialog or clears a kept filter first)  │

🤖 Generated with Claude Code

cliffhall and others added 2 commits October 12, 2026 14:06
Once a `/` filter was kept with Enter, the next Esc fell through to App's
exit accelerator and quit the TUI. A kept filter now claims Esc while its
list has the keyboard: the first Esc clears it, the second exits.

useListFilter reports the claim through a new onEscapeClaimChange effect
(withdrawn on clear, focus loss, modal or unmount, like onEditingChange),
the four list tabs pass it through, and App skips exit() only for Esc —
the other accelerators keep working on the narrowed list. The `?` help
and the kept-filter hint say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
The longer wording truncated at 80 columns. The original text is now
accurate for a kept filter too, and the global Esc row states the order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Oct 12, 2026
@cliffhall
cliffhall requested a balanced review from Copilot October 12, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The Escape ownership lifecycle is correctly scoped and covered by focused regression tests.

0 open findings

What changed in this PR

Fixes TUI Escape handling so a focused, kept list filter is cleared before the application exits.

Changes:

  • Adds Escape-claim reporting and handling across all filterable tabs.
  • Updates filter hints and shortcut help.
  • Adds hook, component, and application-level regression tests.
File Description
clients/​tui/​src/​utils/​keybindings.ts Updates Escape help text.
clients/​tui/​src/​hooks/​useListFilter.ts Clears kept filters and reports Escape ownership.
clients/​tui/​src/​components/​ToolsTab.tsx Forwards the Escape claim.
clients/​tui/​src/​components/​SkillsTab.tsx Forwards the Escape claim.
clients/​tui/​src/​components/​ResourcesTab.tsx Forwards the Escape claim.
clients/​tui/​src/​components/​PromptsTab.tsx Forwards the Escape claim.
clients/​tui/​src/​components/​ListFilterBar.tsx Shows the focused kept-filter hint.
clients/​tui/​src/​App.tsx Defers exit while a filter owns Escape.
clients/​tui/​__tests__/​useListFilter.test.tsx Tests claim lifecycle and Escape consumption.
clients/​tui/​__tests__/​ToolsTab.test.tsx Updates the focused hint expectation.
clients/​tui/​__tests__/​ListFilterBar.test.tsx Tests the new hint.
clients/​tui/​__tests__/​App.test.tsx Covers the reported end-to-end interaction.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed: round 1 (review 5494607889) was clean. It had no inline comments, no suppressed findings, and its headline recommended approval. Per the PR flow, one clean round ends the loop.

@cliffhall
cliffhall merged commit 65c5c2d into v2/main Oct 12, 2026
8 checks passed
@cliffhall
cliffhall deleted the v2/fix/2647-tui-esc-clears-kept-filter branch October 12, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: Esc after keeping a list filter exits the TUI instead of clearing the filter

2 participants