aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core')
-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