aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
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 {