From 2e0803c8d9ec0028c0d018be251c7c2b781247b3 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 22 Sep 2021 00:51:49 +0900 Subject: Implement 'remove_primary_selection' as Alt-, This allows removing search matches from the selection Fixes #713 --- helix-core/src/selection.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'helix-core/src') diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index a3ea2ed4..755ee679 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -360,6 +360,15 @@ impl Selection { self.normalize() } + /// Adds a new range to the selection and makes it the primary range. + pub fn remove(mut self, index: usize) -> Self { + self.ranges.remove(index); + if index < self.primary_index || self.primary_index == self.ranges.len() { + self.primary_index -= 1; + } + self + } + /// 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 { -- cgit v1.2.3-70-g09d2