aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-21 16:23:01 +0000
committerNathan Vegdahl2021-07-21 16:23:01 +0000
commitbc85c85501306f4d3e5e6c802590816cdaf29c13 (patch)
tree2138038ce59284ff7cc04ed950446852d27852c1
parent198fe409513d43bc2c38fbb148131bf8cab58d19 (diff)
Fix selections not being modified quite correctly with text edits.
-rw-r--r--helix-core/src/selection.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index beade27a..3d4ee768 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -109,8 +109,21 @@ impl Range {
/// Map a range through a set of changes. Returns a new range representing the same position
/// after the changes are applied.
pub fn map(self, changes: &ChangeSet) -> Self {
- let anchor = changes.map_pos(self.anchor, Assoc::After);
- let head = changes.map_pos(self.head, Assoc::After);
+ use std::cmp::Ordering;
+ let (anchor, head) = match self.anchor.cmp(&self.head) {
+ Ordering::Equal => (
+ changes.map_pos(self.anchor, Assoc::After),
+ changes.map_pos(self.head, Assoc::After),
+ ),
+ Ordering::Less => (
+ changes.map_pos(self.anchor, Assoc::After),
+ changes.map_pos(self.head, Assoc::Before),
+ ),
+ Ordering::Greater => (
+ changes.map_pos(self.anchor, Assoc::Before),
+ changes.map_pos(self.head, Assoc::After),
+ ),
+ };
// We want to return a new `Range` with `horiz == None` every time,
// even if the anchor and head haven't changed, because we don't