Fix selections not being modified quite correctly with text edits.

pull/376/head
Nathan Vegdahl 3 years ago
parent 198fe40951
commit bc85c85501

@ -109,8 +109,21 @@ impl Range {
/// Map a range through a set of changes. Returns a new range representing the same position /// Map a range through a set of changes. Returns a new range representing the same position
/// after the changes are applied. /// after the changes are applied.
pub fn map(self, changes: &ChangeSet) -> Self { pub fn map(self, changes: &ChangeSet) -> Self {
let anchor = changes.map_pos(self.anchor, Assoc::After); use std::cmp::Ordering;
let head = changes.map_pos(self.head, Assoc::After); 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, // 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 // even if the anchor and head haven't changed, because we don't

Loading…
Cancel
Save