From c400a60377ba25d69130673fe7c307a4bbe733de Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 19 Jul 2021 18:25:36 -0700 Subject: [PATCH] Fix `Selection::push()` to make the pushed range primary. Apparently I accidentally deleted that behavior in the cleanup. --- helix-core/src/selection.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index 7d2526b00..f1625f996 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 {