Skip to content

fix(search): clear find highlights when closing find on a content tab - #950

Merged
eugenioenko merged 1 commit into
eugenioenko:mainfrom
cristianchiriac:fix-find-highlights-content-tab
Oct 18, 2026
Merged

eugenioenko merged 1 commit into
eugenioenko:mainfrom
cristianchiriac:fix-find-highlights-content-tab

Conversation

@cristianchiriac

@cristianchiriac cristianchiriac commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closing the find bar while an image or binary tab was active did nothing to the editor highlights: ClearFindHighlights (and clearSearchState under it) returned early because IsEditorActive() is false on a content tab. The shared Editor still held the previous text tab's SearchQuery and SearchMatches, so switching back to that tab showed the matches highlighted with find closed.

Both functions now clear the shared editor's search state whatever tab is active. g.Editor is always set, and on a content tab it still holds the last text tab's buffer, which is the one the highlights belong to. The retained find query (g.find.query) is untouched, so F3/Shift+F3 keep working as described in the issue.

Closes #939

Evidence

  • New e2e test TestClosingFindOnImageTabClearsTextHighlights (tests/e2e/image_viewer_test.go): searches foo in a text file, switches to a PNG tab, presses Escape, switches back and checks the editor has no search query or matches. Before the fix it fails with highlights after closing find = "foo" [{0 0 3} {1 4 3}], want none; after the fix it passes.
  • go test ./... passes and golangci-lint run reports 0 issues (Go 1.25, Linux container); gofmt -l . is clean.
  • Highlights are colour only, so a --exec text screenshot can't show the difference; the e2e test checks the editor state directly.

Notes

clearSearchState is also used by ClearSearch, so clearing a search while a content tab is active now clears the shared editor too, instead of leaving its highlights for later.

Summary by CodeRabbit

  • Bug Fixes
    • Closing the find overlay while viewing an image now clears search highlights and matches in text files. Returning to a text file no longer shows stale search results.

Closing the find bar while an image or binary tab was active returned
early because no text editor was active, so the shared editor kept the
previous text tab's SearchQuery and SearchMatches. Switching back to
that tab showed the highlights again although find was closed.

ClearFindHighlights and clearSearchState now always clear the shared
editor's search state. The retained find query is kept, so F3 still
works.

Closes #939
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: eugenioenko/ttt/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 52c29aed-6a13-4e9a-b099-9c1fbf7d9085
📥 Commits

Reviewing files that changed from the base of the PR and between 9e3adbb and be64625.

📒 Files selected for processing: 2
  • internal/ui/editor_group.go
  • tests/e2e/image_viewer_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

Closing find now clears the shared editor’s search state when a non-editor tab is active. An end-to-end test checks that closing find on an image tab removes highlights when the text tab is reopened.

Changes: Find highlight clearing

Layer / File(s) Summary
Clear search state on non-editor tabs
internal/ui/editor_group.go, tests/e2e/image_viewer_test.go
ClearFindHighlights clears the shared editor’s search state without requiring an editor tab to be active. The end-to-end test closes find on an image tab and checks that the text tab has no search query or matches.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to be646

Closing find on an image tab clears the text highlights, and the regression test checks that behavior. The change is mergeable after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: clearing find highlights when closing find on a content tab.
Linked Issues check Passed Issue #939 requires clearing shared editor highlights when find closes on a content tab, retaining the find query, and adding an end-to-end regression test. ClearFindHighlights and `clearSearchState…
Out of Scope Changes check Passed The changes are limited to the search-state behavior in internal/ui/editor_group.go and its focused end-to-end regression test in tests/e2e/image_viewer_test.go. Both changes directly support issu…
Full details: Linked Issues check

Explanation

Issue #939 requires clearing shared editor highlights when find closes on a content tab, retaining the find query, and adding an end-to-end regression test. ClearFindHighlights and clearSearchState no longer return for non-editor tabs and clear Editor.SearchQuery, Editor.SearchMatches, and Editor.SearchActive. They do not modify g.find.query. TestClosingFindOnImageTabClearsTextHighlights reproduces the text-to-image sequence and verifies that the text editor has no query or matches after returning.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the search-state behavior in internal/ui/editor_group.go and its focused end-to-end regression test in tests/e2e/image_viewer_test.go. Both changes directly support issue #939.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@eugenioenko eugenioenko left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@cristianchiriac Nice fix, thank you for the patch :)

@eugenioenko
eugenioenko merged commit 42df941 into eugenioenko:main Oct 18, 2026
13 checks passed
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.

Find highlights come back after closing find on an image or binary tab

2 participants