Fix `Selection::push()` to make the pushed range primary.

Apparently I accidentally deleted that behavior in the cleanup.
pull/376/head
Nathan Vegdahl 3 years ago
parent 13b0784009
commit c400a60377

@ -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 {

Loading…
Cancel
Save