-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhanced surround_replace
to provide visual feedback
#7588
enhanced surround_replace
to provide visual feedback
#7588
Conversation
a4dbf22
to
0d022d2
Compare
0d022d2
to
3dc4ad9
Compare
When the target character is pressed, the selection is temporarily updated to display the affected positions. It restores the original selection after the operation is cancelled or completed.
3dc4ad9
to
f26677d
Compare
a936383
to
6705e0f
Compare
6705e0f
to
a558743
Compare
surround_replace
to provide visual feedback
ca77e5b
to
78fa40e
Compare
78fa40e
to
6127ff3
Compare
helix-term/src/commands.rs
Outdated
@@ -5115,11 +5115,15 @@ fn surround_replace(cx: &mut Context) { | |||
} | |||
}; | |||
|
|||
let selection = selection.clone(); | |||
let ranges: SmallVec<_> = change_pos.iter().map(|&pos| Range::point(pos)).collect(); | |||
doc.set_selection(view.id, Selection::new(ranges, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, one last thing: you need to compute the correct primary_idx here or the view will be moved if you have a lot of selections: if you selected all the lines in a very big file and were viewing somewhere further down, an index of 0 would move the view all the way to the top
Something like
let primary = selection.primary();
let (i, _) = ranges.iter().enumerate().find(|_i, range| range.overlaps(primary))...
Selection::new(ranges, i)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I've pushed this change and so far so good during smoke testing, but I wonder if there's a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a better way. There should be twice as many matches (surrounding positions) as original selections, so the primary index of this selection is twice the original selection primary index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good to me, nice visual improvement with very little additional complexity added. Great job!
When the target character is pressed, the selection is temporarily updated to display the affected positions. It restores the original selection after the operation is cancelled or completed.