-
-
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
Scrolling view keeps selections #1420
Conversation
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.
Nice, thank you!
// TODO: only manipulate main selection | ||
doc.set_selection(view.id, Selection::single(anchor, head)); | ||
// replace primary selection with an empty selection at cursor pos | ||
let prim_sel = Range::new(anchor, head); |
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.
Do we need to clone, or is it possible just to mutate the primary range that we already got from above?
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.
Selections are currently not mutably accessible outside Document. I believe this protects the Integrity of the selections, e.g. not having overlapping selections (see:
helix/helix-core/src/selection.rs
Line 523 in aaa42e1
pub fn ensure_invariants(self, text: RopeSlice) -> Self { |
Ranges and Selections are pretty lightweight too: Range is 3 usize
and Selection is 1 vec of Ranges + 1 usize
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.
Yeah, but Range: Copy
, and Selection::primary
returns an owned Range, which is its own copy, if I'm not mistaken.
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.
I'm not sure to get your point. Currently, Document::set_selection
is the only way to modify selections and it asks for a owned Selection
, so a copy of Selection is required anyway. The Ranges inside Selections are not mutable in any way so a copy or a new range is also required.
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.
Sorry, I see what you mean now: Selection::replace
takes a mut self
, so cloning is necessary. Never mind me.
Thanks! 🎉 |
Fixes #917.
This is the same behavior as in Kakoune. I believe in vim / nvim it would grow / shrink the main selection instead of deleting it.