Skip to content

fix(terminal): clear stale search highlights when find closes - #9519

Merged
nwparker merged 1 commit into
stablyai:mainfrom
kaynansc:kaynansc/fix-desktop-find-search
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
kaynansc:kaynansc/fix-desktop-find-search

Conversation

@kaynansc

@kaynansc kaynansc commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

fix(terminal): clear stale search highlights when find closes

Summary

Fixes stale terminal find highlights that lingered after the query was erased, the active pane changed, or the search overlay unmounted.

ELI5

When you searched in the terminal and then cleared or closed the search, the highlighted match sometimes stayed lit up. Now it disappears the moment the search stops.

Root cause & fix

SearchAddon.clearDecorations() removes xterm's painted match decorations but leaves the active match still selected, and TerminalSearch never cleaned up the previous addon when its portal moved to another pane or unmounted. The fix adds a clearTerminalSearch() helper that pairs clearDecorations() with a findNext('') empty-find request — xterm's path for dropping the active selection — and applies it on query erase, search-closed, addon change, and portal unmount. A separate addon-lifecycle effect keyed on searchAddon cleans the previous pane without resetting incremental search on every keystroke.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • Rebase: clean onto origin/main (base 8a23618310, head b20b6ecbc2).
  • Test file src/renderer/src/components/TerminalSearch.test.tsx (new) — 3/3 pass on branch.
  • Reverting only the fix (TerminalSearch.tsx) while keeping the test → 3/3 fail, proving the tests catch the regression:
On branch:  Test Files 1 passed (1); Tests 3 passed (3)
Fix reverted:
  Test Files 1 failed (1); Tests 3 failed (3)
  - "clears the current addon when the query is erased":
      expected findNext called with [''], Number of calls: 0
  - "clears the previous addon when the search moves to another pane":
      expected clearDecorations called 1 time, got 0
  - "clears the addon when the search portal unmounts":
      expected clearDecorations called 1 time, got 0
  • Lint: npx oxlint src/renderer/src/components/TerminalSearch.tsx — clean (no warnings/errors).

Trade-offs

None — pure fix. (Searching history owned internally by an alternate-screen TUI remains a separate, pre-existing limitation, since that history is not in xterm's active buffer.)

Regression risk

Effectively zero. The change is renderer-only and scoped to the terminal-search cleanup path: cleanup runs only when search is cleared/closed, the addon changes, or the portal unmounts. Non-affected code paths are byte-identical to origin/main, and the empty-find call short-circuits without scanning the buffer. The three regression tests prove correct behavior across all three failure paths.

Credit to @kaynansc for the original fix. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

@kaynansc
kaynansc marked this pull request as ready for review July 20, 2026 05:18
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

TerminalSearch now uses a shared cleanup helper that clears Xterm decorations and resets search navigation with an empty query. Cleanup runs when the search closes, the query is erased, the search addon changes, or the component unmounts. A new test suite verifies these behaviors for query clearing, addon switching, and unmount cleanup.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the core fix: clearing stale terminal search highlights when the find UI closes.
Description check ✅ Passed It covers the main change, rationale, validation, and risk, so it is mostly complete despite using custom headings.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 20, 2026 18:25
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:35
@nwparker
nwparker force-pushed the kaynansc/fix-desktop-find-search branch from b20b6ec to f89a91b Compare July 23, 2026 11:49
@nwparker
nwparker merged commit b5ae776 into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much for this, @kaynansc — clear stale search highlights when find closes. Verified (fail-on-main/pass-on-branch), rebased on latest main, reviewed, and merged. Really appreciate 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.

5 participants