aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-20 01:25:36 +0000
committerNathan Vegdahl2021-07-20 01:25:36 +0000
commitc400a60377ba25d69130673fe7c307a4bbe733de (patch)
treee7473eec34335580d15927fbb2a12a1ab187eb83 /helix-core
parent13b0784009cd0c1150ba7fac2bac1465360be6dd (diff)
Fix `Selection::push()` to make the pushed range primary.
Apparently I accidentally deleted that behavior in the cleanup.
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/selection.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index 7d2526b0..f1625f99 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -290,11 +290,12 @@ impl Selection {
}
}
+ /// Adds a new range to the selection and makes it the primary range.
pub fn push(mut self, range: Range) -> Self {
self.ranges.push(range);
+ self.set_primary_index(self.ranges().len() - 1);
self.normalize()
}
- // replace_range
/// Map selections over a set of changes. Useful for adjusting the selection position after
/// applying changes to a document.
@@ -320,6 +321,11 @@ impl Selection {
self.primary_index
}
+ pub fn set_primary_index(&mut self, idx: usize) {
+ assert!(idx < self.ranges.len());
+ self.primary_index = idx;
+ }
+
#[must_use]
/// Constructs a selection holding a single range.
pub fn single(anchor: usize, head: usize) -> Self {