on master help sign in
Fix selections not being modified quite correctly with text edits.
commitbc85c85501306f4d3e5e6c802590816cdaf29c13 authorNathan Vegdahl <cessen@cessen.com> dateWed 21 Jul 2021, 09:23 (5 years ago) parent198fe40
1 file changed+15−2
helix-core/src/selection.rs+15−2
helix-core/src/selection.rs+15−2
@@ -109,8 +109,21 @@ impl Range {
109109 /// Map a range through a set of changes. Returns a new range representing the same position
110110 /// after the changes are applied.
111111 pub fn map(self, changes: &ChangeSet) -> Self {
112− let anchor = changes.map_pos(self.anchor, Assoc::After);
113− let head = changes.map_pos(self.head, Assoc::After);
112+ use std::cmp::Ordering;
113+ let (anchor, head) = match self.anchor.cmp(&self.head) {
114+ Ordering::Equal => (
115+ changes.map_pos(self.anchor, Assoc::After),
116+ changes.map_pos(self.head, Assoc::After),
117+ ),
118+ Ordering::Less => (
119+ changes.map_pos(self.anchor, Assoc::After),
120+ changes.map_pos(self.head, Assoc::Before),
121+ ),
122+ Ordering::Greater => (
123+ changes.map_pos(self.anchor, Assoc::Before),
124+ changes.map_pos(self.head, Assoc::After),
125+ ),
126+ };
114127
115128 // We want to return a new `Range` with `horiz == None` every time,
116129 // even if the anchor and head haven't changed, because we don't