Skip to content

feat(terminal): find bar over the scrollback - #843

Open
opticon454 wants to merge 1 commit into
Ark0N:masterfrom
opticon454:feature/terminal-find-bar
Open

opticon454 wants to merge 1 commit into
Ark0N:masterfrom
opticon454:feature/terminal-find-bar

Conversation

@opticon454

Copy link
Copy Markdown
Contributor

What

A find bar over the terminal's scrollback. Ctrl+Shift+F (Cmd+Shift+F on a Mac) opens it, type to search, Enter and Shift+Enter for the next and previous match with a count, Esc to close. It uses @xterm/addon-search, bundled like the other xterm addons. On by default; terminalFindEnabled in App Settings > Scrolling & rendering (an absent key means on).

This is the find bar half of #842, split out as the maintainer asked. It does not depend on the saved history store.

Review items from #842 this covers

  • Shortcut registry. The chord is the rebindable find-in-terminal entry in DEFAULT_SHORTCUTS, so it shows in the Ctrl+? overlay (zh-CN label added) and in the keyboard-shortcut paragraph of src/web/CLAUDE.md. Like copy-selection it is dispatched by isTerminalFindChord() and absent from SHORTCUT_ACTIONS, so with the setting off the chord reaches the terminal untouched.
  • Escape. The global capture-phase Escape handler returns early for an Escape inside #terminalFindBar, so Esc in the bar closes the bar and not App Settings or a side panel behind it.
  • Tile grid. The SearchAddon is on the main terminal only, so terminalFindEnabled() is false while _tilesOwnTerminal() is true: the chord is not taken and the bar does not open.
  • The setting row moved out of Cross-session features to Scrolling & rendering.

Known limit

It searches what the browser holds. A CLI that keeps its older text itself (Claude's fullscreen view) has only the screen in the terminal, so only what is on screen is found. The Settings text and docs/wiki/Settings-Reference.md say so.

Testing

test/terminal-find.test.ts (new). npm run typecheck, eslint and format:check are clean. Full npm test on this branch: the zh-CN label test failed on the first run and is fixed here; the only other failure is test/remote-pane-command-shell.test.ts "starts /bin/sh when SHELL is unset", which fails identically on a clean upstream/master. Driven in headless Chromium against a running server: the chord opens the bar, the count reads 1 of 80, Esc in the bar leaves App Settings open, the overlay lists it, and the bar stays closed while the tile grid owns the terminal.

No changeset added (generated at release).

Ctrl/Cmd+Shift+F opens a find bar over the terminal's scrollback, using
@xterm/addon-search. On by default (terminalFindEnabled, App Settings >
Scrolling & rendering). The chord is the rebindable registry entry
find-in-terminal, so it shows in the Ctrl+? overlay. Esc inside the bar
closes only the bar. It stays off while the tile grid owns the terminal,
whose parked main terminal is not the focused tile.
@Ark0N

Ark0N commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks for splitting this out of #842 so quickly. The PR adds a Ctrl+Shift+F find bar over the main terminal's scrollback, built on xterm's SearchAddon, with a rebindable registry entry and a synced on/off setting. The registry entry, the Escape early return and the tile-grid gate are all in place, and typecheck, lint, format, the frontend checks and the full npm test pass here.

I also drove the bar in headless Chromium against a dev server. A few edges need changes before this can merge.

Needs a change

  1. src/web/public/terminal-ui.js:7641 (terminalFindEnabled()): the chord is taken no matter what is on screen. With App Settings open, Ctrl+Shift+F opens the bar behind the modal and moves focus into its input, so typing lands in a field nobody can see (and it re-runs the last search, which scrolls the terminal behind the modal). On the home screen the bar opens on top of the welcome overlay, because its z-index 30 is above the overlay's 10, and a bar left open stays there after showWelcome(). Please only take the chord when the terminal is what the user is looking at. For example, return false while #welcomeOverlay has .visible or a modal or overlay is open, or check the focus target the way shouldOpenCommandPaletteFromShortcut() does. Please also close the bar from showWelcome().
  2. src/web/public/terminal-ui.js:7671 (closeTerminalFind()): the SearchAddon selects each match with terminal.select(), and that selection is still there after the bar closes. Codeman's Ctrl+C copies a selection before it interrupts, so the first Ctrl+C after a search copies the match instead of stopping the agent. I reproduced it with sleep 300 in a shell session: find, Esc, Ctrl+C, and the sleep kept running. Only the second press interrupted it. Please clear the selection when the bar closes (this.terminal?.clearSelection()).
  3. src/web/public/terminal-ui.js:7717 (_terminalFindStep()): with Auto Copy on, each step's selection arms _autoCopyPending, and the next mouseup anywhere copies the match. Clicking the bar's Next button replaced my clipboard with needle. Clearing _autoCopyPending is not enough by itself, because decideAutoCopy() also copies text that differs from the last auto-copy. The flush has to leave the find's own selection alone.
  4. test/terminal-find.test.ts: every assertion checks source text. Please add tests that run the real code for the gates: the setting, the tile grid, the visibility or focus gate from item 1, and clearing the selection on close from item 2. You could call the prototype methods with a small fake this, or write a *.browser.test.ts listed in BROWSER_TEST_GLOBS.
  5. Docs: please add Ctrl+Shift+F to the Terminal table in docs/wiki/Keyboard-Shortcuts.md (next to line 33) and to the shortcut table in README.md (next to line 773).

Smaller things (fine in this round or at merge time)

  • src/web/CLAUDE.md, Z-index layers: add the find bar (30, inside .terminal-wrap) to the list.
  • src/web/public/terminal-ui.js:7736: the "N+" form is picked on resultIndex === -1, which also happens under the 1000-match cap when the active decoration was not created, so 80 matches can show as "80+". Base the "+" on r.resultCount >= 1000 instead.
  • src/web/public/terminal-ui.js:10: add vendor/xterm-addon-search.min.js (SearchAddon) to the @fileoverview dependencies.

Once items 1 to 5 are fixed this is ready to merge, and #842 can rebase onto it.

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.

2 participants