Skip to content

Commit

Permalink
Fix shrink_selection with multiple cursors. (#6093)
Browse files Browse the repository at this point in the history
* Fix #6092

Cause were some incorrect assumptions that missed an edge case in the
`Selection.contains()` calculation. Tests were added accordingly.

* Fix Selection.contains() edge-case handling.

Removing the len check short-circuit was the only thing needed as
pointed out by @dead10ck.
  • Loading branch information
gibbz00 authored Mar 9, 2023
1 parent aabc8af commit 2cf4ce2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 6 additions & 5 deletions helix-core/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,6 @@ impl Selection {

// returns true if self ⊇ other
pub fn contains(&self, other: &Selection) -> bool {
// can't contain other if it is larger
if other.len() > self.len() {
return false;
}

let (mut iter_self, mut iter_other) = (self.iter(), other.iter());
let (mut ele_self, mut ele_other) = (iter_self.next(), iter_other.next());

Expand Down Expand Up @@ -1240,5 +1235,11 @@ mod test {
vec!((3, 4), (7, 9))
));
assert!(!contains(vec!((1, 1), (5, 6)), vec!((1, 6))));

// multiple ranges of other are all contained in some ranges of self,
assert!(contains(
vec!((1, 4), (7, 10)),
vec!((1, 2), (3, 4), (7, 9))
));
}
}
1 change: 0 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4371,7 +4371,6 @@ fn shrink_selection(cx: &mut Context) {
// try to restore previous selection
if let Some(prev_selection) = view.object_selections.pop() {
if current_selection.contains(&prev_selection) {
// allow shrinking the selection only if current selection contains the previous object selection
doc.set_selection(view.id, prev_selection);
return;
} else {
Expand Down

0 comments on commit 2cf4ce2

Please sign in to comment.