summaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/selection.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index 18af4d08..f3b5d2c8 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -362,6 +362,11 @@ impl Selection {
/// Adds a new range to the selection and makes it the primary range.
pub fn remove(mut self, index: usize) -> Self {
+ assert!(
+ self.ranges.len() > 1,
+ "can't remove the last range from a selection!"
+ );
+
self.ranges.remove(index);
if index < self.primary_index || self.primary_index == self.ranges.len() {
self.primary_index -= 1;
@@ -369,6 +374,12 @@ impl Selection {
self
}
+ /// Replace a range in the selection with a new range.
+ pub fn replace(mut self, index: usize, range: Range) -> Self {
+ self.ranges[index] = range;
+ self.normalize()
+ }
+
/// Map selections over a set of changes. Useful for adjusting the selection position after
/// applying changes to a document.
pub fn map(self, changes: &ChangeSet) -> Self {