Skip to content

Conversation

@smitbarmase
Copy link
Member

@smitbarmase smitbarmase commented Feb 13, 2025

Closes #12635

  • Get it working
  • Disable for multi cursor
  • Disable for vim visual line selection
  • Add setting to disable it
  • Add scrollbar marker
  • Handle delete state capturing selection

Preview:

updated.mp4

Release Notes:

  • Added support to highlight all matching occurrences of text within the selection in editor.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 13, 2025
@smitbarmase smitbarmase marked this pull request as draft February 14, 2025 09:24
@nickmachairas
Copy link

@0xtimsb thanks for working on this. One suggestion: please add markers on the scrollbar on the right not just for where the cursor is at but also where the highlighted text is. The benefit is quickly identifying text anywhere in the editor, not just the area visible in the window. I am not describing anything new, this is how it is done in VSC. Thanks again

@lanternlogic
Copy link

Looks great! But yes, please add the scrollbar occurrences view. Massive help when identifying these tokens. Many thanks!

@smitbarmase smitbarmase force-pushed the highlight-all-matching branch from a1c708b to d3637a3 Compare February 17, 2025 18:10
@smitbarmase smitbarmase marked this pull request as ready for review February 17, 2025 19:03
@smitbarmase smitbarmase merged commit 3e97226 into main Feb 17, 2025
14 checks passed
@smitbarmase smitbarmase deleted the highlight-all-matching branch February 17, 2025 19:21
Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

🚀

let buffer_ranges =
vec![buffer.anchor_before(0)..buffer.anchor_after(buffer.len())];
let query = buffer.text_for_range(selection.range()).collect::<String>();
for range in buffer_ranges {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit odd: we create a non-mut vec![buffer.anchor_before(0)..buffer.anchor_after(buffer.len())] and then iterate it?
Can unwrap the entire loop it seems.


One potential super nice feature could be expanding a single, empty selection (basically, a caret) to the ends of the word with movement::surrounding_word: then, we can implement highlights like

image

which we do with tree-sitter.

}
let selection = self.selections.newest::<Point>(cx);
if selection.is_empty() || selection.start.row != selection.end.row {
self.clear_background_highlights::<SelectedTextHighlight>(cx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, we could test all these clear_background_highlights cases.

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

None yet

Development

Successfully merging this pull request may close these issues.

Highlight all matching occurrences of text in selection

6 participants