on master help sign in
Fix `shrink_selection` with multiple cursors. (#6093)
2cf4ce2gibbz00
helix-core/src/selection.rs+6−5
@@ -625,11 +625,6 @@ impl Selection {
625
625
626 // returns true if self ⊇ other
626 // returns true if self ⊇ other
627 pub fn contains(&self, other: &Selection) -> bool {
627 pub fn contains(&self, other: &Selection) -> bool {
628− // can't contain other if it is larger
629− if other.len() > self.len() {
630− return false;
631− }
632−
633 let (mut iter_self, mut iter_other) = (self.iter(), other.iter());
628 let (mut iter_self, mut iter_other) = (self.iter(), other.iter());
634 let (mut ele_self, mut ele_other) = (iter_self.next(), iter_other.next());
629 let (mut ele_self, mut ele_other) = (iter_self.next(), iter_other.next());
635
630
@@ -1240,5 +1235,11 @@ mod test {
1240 vec!((3, 4), (7, 9))
1235 vec!((3, 4), (7, 9))
1241 ));
1236 ));
1242 assert!(!contains(vec!((1, 1), (5, 6)), vec!((1, 6))));
1237 assert!(!contains(vec!((1, 1), (5, 6)), vec!((1, 6))));
1238+
1239+ // multiple ranges of other are all contained in some ranges of self,
1240+ assert!(contains(
1241+ vec!((1, 4), (7, 10)),
1242+ vec!((1, 2), (3, 4), (7, 9))
1243+ ));
1243 }
1244 }
1244}
1245}
helix-term/src/commands.rs−1
@@ -4371,7 +4371,6 @@ fn shrink_selection(cx: &mut Context) {
4371 // try to restore previous selection
4371 // try to restore previous selection
4372 if let Some(prev_selection) = view.object_selections.pop() {
4372 if let Some(prev_selection) = view.object_selections.pop() {
4373 if current_selection.contains(&prev_selection) {
4373 if current_selection.contains(&prev_selection) {
4374− // allow shrinking the selection only if current selection contains the previous object selection
4375 doc.set_selection(view.id, prev_selection);
4374 doc.set_selection(view.id, prev_selection);
4376 return;
4375 return;
4377 } else {
4376 } else {