Repository navigation
fix(terminal): keep find-bar highlights when navigating with Cmd+G / Cmd+Shift+G - #18844
Conversation
|
No actionable comments were generated in the recent review. ℹ️ Recent review info
Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
ℹ️ No critical issues — one edge case in the match counter and one coverage gap worth a look.
Reviewed changes
- Shared
buildTerminalSearchOptionsbuilder — extracts the decoration palette and search flags intoterminal-search-options.tsso both the find bar and the Cmd+G shortcut construct the same options, eliminating the drift that caused the bug. - Shortcut navigation now carries
decorations—runTerminalSearchNavigationbuilds options through the shared helper, so Cmd+G moves the active-match decoration, firesonDidChangeResults, and keeps highlights refreshing on write. - Match counter — subscribes to
searchAddon.onDidChangeResultsand renders a3/47counter (red0/0for no matches), cleared on empty query and pane switch; subscription effect is declared before the search effect. - Tests — regression test asserting shortcut navigation passes
decorations.activeMatchBackground, plus counter tests for reported position/total and clearing.
The root-cause analysis checks out: in SearchAddon.ts, _selectResult only creates the active decoration when searchOptions?.decorations is set, _fireResults passes !!searchOptions?.decorations to fireResultsChanged (which returns early when false), and _updateMatches gates on lastSearchOptions?.decorations. Passing decorations on the navigation path is exactly the right fix.
ℹ️ Nitpicks
- The red
0/0(zero-match) branch is the one behavior the PR body calls out that has no test. Thematches.count === 0 ? 0 : ...ternary in the render is a distinct branch — a test emitting{ resultIndex: -1, resultCount: 0 }would pin it.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Ready for review — every template section is filled in, and before/after evidence is now embedded in the description. One thing that needs a maintainer: this is a fork PR from a first-time contributor, so the lint/typecheck/test/build workflows are held pending approval. Only |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
formatMatchCountcounter formatter — extracts theindex < 0branch into a pure helper so a selection past the highlight limit renders1000+(or the bare total when no match is selected) instead of the misleading0/1000, resolving the prior review's counter edge case.- Addon/query-tagged match state —
MatchCountnow carries theSearchAddonandrequestQueryit was reported for, andcurrentMatchesis derived in render, so a pane switch or emptied/edited query invalidates the counter without the removedsetMatches(null)resets (which also cleared thereact-doctorfinding). - Pinned highlight limit —
TERMINAL_SEARCH_HIGHLIGHT_LIMIT = 1000is set at addon construction inpane-dom-creation.ts, matching the addon's verified default so the counter knows whereresultCountis truncated. - Expanded tests — new assertions pin the red
0/0, the1000+cap, and the bare-total-when-unselected branches, closing the prior zero-match coverage gap.
The prior inline finding is fully addressed: formatMatchCount branches on index < 0 before falling through to index + 1 / count, and the 1000+/bare-total tests exercise exactly that path. The highlight limit is confirmed identical to the addon's Constants.DEFAULT_HIGHLIGHT_LIMIT (1000) and is not altered by the vendored patch, so the constructor pin is behavior-neutral as claimed.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…Cmd+Shift+G
The Cmd+G / Cmd+Shift+G path called findNext/findPrevious with only
{ caseSensitive, regex }. @xterm/addon-search only draws the active-match
decoration, fires onDidChangeResults, and keeps refreshing highlights on new
output when the call carries decorations, so the shortcut froze the active
highlight and the match counter.
Share one buildTerminalSearchOptions() between the find bar and the
shortcut path so both send the same decorated options.
Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
0d5833f to
610c6a9
Compare

ELI5
When you search inside a terminal, the find bar highlights every match and shows which one you're on. Clicking the find bar's arrows or pressing Enter worked. Pressing Cmd+G or Cmd+Shift+G (Ctrl+G on Windows/Linux) did move to the next match, but the orange "current match" highlight stayed put, the
3/47counter froze, and highlights stopped updating when new output came in. The shortcut was sending the search without the "please highlight" settings. Now the shortcut and the find bar send the same settings, so they behave the same.What Changed
src/renderer/src/components/terminal-search-options.tswith onebuildTerminalSearchOptions(). It holds the decoration palette, moved unchanged fromTerminalSearch.tsx.TerminalSearch.tsxbuilds its options with this helper. Its behavior doesn't change.runTerminalSearchNavigationinterminal-keyboard-shortcut-matching.tsnow passes the decorated options tofindNext/findPrevious. Before, it passed only{ caseSensitive, regex }.runTerminalSearchNavigationtests now check that the shortcut sendsdecorations. They previously asserted the buggy bare options.Why
@xterm/addon-searchdecides three things from whether the last find call includeddecorations:_selectResultonly creates the active-match decoration when it gets options.fireResultsChanged(!!decorations)returns early without them, soonDidChangeResults(which drives the counter) never fires._updateMatchescheckslastSearchOptions?.decorationsbefore it re-highlights after new output.The shortcut's bare options replaced
lastSearchOptions, which turned all three off. Having one options builder for both paths means they can't drift apart again.This version is smaller than the original PR.
mainalready has a match counter subscribed toonDidChangeResults(including theN+overflow formatting), so this PR leaves out the original's counter,highlightLimitpin, and JSDoc additions. With this fix, the existing counter now follows Cmd+G.Linked Issue
Fixes #18843
Visual Proof
No screenshot or video. The proof is a before/after probe that runs a real xterm
Terminal+SearchAddonin happy-dom. NEEDLE appears only in scrollback rows 0-45 of 350:Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Reproduced the bug on
origin/mainwith the probe above. Event index stuck at 0, no active decoration, no refresh after output, and the regex + case-sensitive shortcut path also stopped emitting results. All pass on this branch.vitest run keyboard-handlers.test.ts TerminalSearch*: 31/31 pass after rebasing on currentmain.oxlintandoxfmt --checkare clean on the 4 touched files.No Electron run. The change is renderer-only and has no platform-specific code (the shortcut is already platform-aware upstream of this function), so macOS, Linux and Windows behave the same.
Review
decorationsdirectly instead of rebuilding the expected value from the production helper, so they'd catch a regression.highlightLimit.Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Original fix by @AntonioKL in #18844. Their authorship is kept on the squashed commit.