@@ -109,8 +109,21 @@ impl Range {
109 /// Map a range through a set of changes. Returns a new range representing the same position
109 /// Map a range through a set of changes. Returns a new range representing the same position
110 /// after the changes are applied.
110 /// after the changes are applied.
111 pub fn map(self, changes: &ChangeSet) -> Self {
111 pub fn map(self, changes: &ChangeSet) -> Self {
112+ use std::cmp::Ordering;
113+ let (anchor, head) = match self.anchor.cmp(&self.head) {
114+ Ordering::Equal => (
112− let anchor = changes.map_pos(self.anchor, Assoc::After);
115+ changes.map_pos(self.anchor, Assoc::After),
116+ changes.map_pos(self.head, Assoc::After),
119+ changes.map_pos(self.anchor, Assoc::After),
120+ changes.map_pos(self.head, Assoc::Before),
122+ Ordering::Greater => (
113− let head = changes.map_pos(self.head, Assoc::After);
123+ changes.map_pos(self.anchor, Assoc::Before),
124+ changes.map_pos(self.head, Assoc::After),
115 // We want to return a new `Range` with `horiz == None` every time,
128 // We want to return a new `Range` with `horiz == None` every time,
116 // even if the anchor and head haven't changed, because we don't
129 // even if the anchor and head haven't changed, because we don't