Skip to content

editor: Add search highlighting for active elements#35931

Closed
DarkMatter-999 wants to merge 16 commits intozed-industries:mainfrom
DarkMatter-999:feat/enhance-find-select-highlight
Closed

editor: Add search highlighting for active elements#35931
DarkMatter-999 wants to merge 16 commits intozed-industries:mainfrom
DarkMatter-999:feat/enhance-find-select-highlight

Conversation

@DarkMatter-999
Copy link
Contributor

Closes #28617

Release Notes:

  • Improved search text highlighting, the currently selected search result is highlighted in a different shade improving visibility.

Before

image

After

image

@cla-bot
Copy link

cla-bot bot commented Aug 9, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @DarkMatter-999 on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@DarkMatter-999
Copy link
Contributor Author

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Aug 9, 2025
@cla-bot
Copy link

cla-bot bot commented Aug 9, 2025

The cla-bot has been summoned, and re-checked this pull request!

@maxdeviant maxdeviant changed the title Editor: Add search highlighting for active elements editor: Add search highlighting for active elements Aug 9, 2025
Copy link
Member

@smitbarmase smitbarmase left a comment

Choose a reason for hiding this comment

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

Looks good, just left few notes.

@DarkMatter-999
Copy link
Contributor Author

@smitbarmase, made the required changes, please re-review.

                "search.match_background": "#00FF007F",
                "search.active_match_background": "#FF00007F",
image

Copy link
Member

@smitbarmase smitbarmase left a comment

Choose a reason for hiding this comment

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

We are almost there.

  1. I think it would be great to actually define sensible colors for at least the theme we support out of the box. You can find them in assets/themes. It should be distinct enough or straight up complementary, since even with two matches you should be able to identify which one is active.

Zed with this PR:

VSCode:

Sublime:

  1. We also don't want to break any theme, since after this change, active highlight might start to look different for different themes. I think we should fallback to search_match_background if search_active_match_background is not specified. Right now, fallback works only if both search_match_background and search_active_match_background aren't specified.

pub tab_bar_background: Hsla,
pub tab_inactive_background: Hsla,
pub tab_active_background: Hsla,

Copy link
Member

Choose a reason for hiding this comment

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

I think it's alright to not have these comments, since variable naming is apparent.

@DarkMatter-999
Copy link
Contributor Author

Hey @smitbarmase I've updated the default themes and added backward compatibility for other themes as fallback to search_match_background. Please review.

@smitbarmase
Copy link
Member

Hey @DarkMatter-999, after digging deeper into this, I found a major issue with the approach. Using a separate highlight key for the active match might not be the best idea because:

  1. If you need to query all match highlights, it becomes harder to merge the active match with the non-active ones. For example, get_matches expects everything in sorted order. With the current state of this PR, the Outline Panel breaks because it expects a full sorted list. We’d have to binary-search the correct position for the active match and then return it, which is unnecessary extra work.

  2. Similarly, in update_matches, the check existing_range != Some(matches) will always fail, since it’s comparing all matches with only the non-active ones. We’d have to manually construct the correct ordered list there too. If you add a dbg in the current version, you’ll notice how often this method runs, because that check always fails and triggers MatchesInvalidated.

I started from scratch and after experimenting, I ended up with this PR: #44098. Thanks to you for the theme changes, I cherry-picked them as is. Thanks for your contribution! I’m closing this in favor of that PR.

@smitbarmase smitbarmase closed this Dec 3, 2025
@github-project-automation github-project-automation bot moved this from Community PRs to Done in Quality Week – December 2025 Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

Development

Successfully merging this pull request may close these issues.

Highlight looks identical for selected and unselected find results

4 participants