-
-
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
feat(commands): shrink_selection #1340
Conversation
Showcase: Screen.Recording.2021-12-23.at.11.01.31.mov |
@archseer I refactored the |
I am also wondering about the keybindings. @archseer suggested |
I think I would prefer the latter (repeating with the dot). Similar to how |
|
Oh sorry, I meant Alt-. which repeats the last movement |
Added default key mapping to |
helix-core/src/selection.rs
Outdated
|
||
pub fn contains(&self, other: &Selection) -> bool { | ||
self.iter() | ||
.zip(other.iter()) |
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.
Hmm. This won't work correctly if I have three selection ranges and then I call contains with two selection ranges that are a subset of the original selection
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, you are right. I reworked the method but I am still hesitant whether the check makes sense at all. I think just moving the cursor should disable the shrink_selection
so that we are safe, but I guess we can adjust that later if there are any complaints?
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 was pondering this. I think just checking containment will do the right thing when the user flow is expand, expand, shrink, shrink, etc, but you could also have the following sequence
fn foo() {
let a = 1;
[a]
}
expand
fn foo() [{
let a = 1;
a
}]
move cursor around and back inside the function
fn foo() {
[] let a = 1;
a
}
select entire file
[
...
fn foo() {
let a = 1;
a
}
...
]
shrink selection
fn foo() {
let a = 1;
[a]
}
It might not matter much in practice. But I guess we just have to decide how strict we want to be.
I think this shouldn't necessarily be a blocker, but one thing we could do if there haven't been any expands before shrinks is just select the first child node. |
I thought that was already the behavior? I proposed that before: when we run out of selections on the stack it should select the first child instead |
Well, if I'm not mistaken, the current PR does not do anything unless there was previously an expand to populate the selection history. |
Yes, this is the case. |
helix-term/src/commands.rs
Outdated
doc.set_selection(view.id, prev_selection); | ||
} else { | ||
// clear existing selection as they can't be shrinked to anyway | ||
view.object_selections.clear() |
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.
Can you add that behavior in here? It should call object::shrink_selection
and just look for the first descendant_for_byte_range
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.
Done, can you please check whether I understood the requirement correctly?
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.
It looks right to me now 🙂
Add `shrink_selection` command that can be used to shrink previously expanded selection. To make `shrink_selection` work it was necessary to add selection history to the Document since we want to shrink the selection towards the syntax tree node that was initially selected. Selection history is cleared any time the user changes selection other way than by `expand_selection`. This ensures that we don't get some funky edge cases when user calls `shrink_selection`. Related: #1328
Add
shrink_selection
command that can be used to shrink previously expanded selection.To make
shrink_selection
work it was necessary to add selection history to the Document since we want to shrink the selection towards the syntax tree node that was initially selected.Selection history is cleared any time the user changes selection other way than by
expand_selection
. This ensures that we don't get some funky edge cases when user callsshrink_selection
.Related: #1328