aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorPascal Kuthe2023-06-22 21:37:39 +0000
committerBlaž Hrastnik2023-06-25 16:32:31 +0000
commitb33516fb16df93572ac4ddec1d4079282a2b4b5a (patch)
treedde289fd6b44b9136a14f57fa5488ae4b3ccc6e7 /helix-core
parentd491e234f4eb4d8c3869f44ab71fedf022dc463e (diff)
move normalize fastpath into normalize function
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/selection.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index 0539c9f6..9104c209 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -451,15 +451,8 @@ impl Selection {
/// Map selections over a set of changes. Useful for adjusting the selection position after
/// applying changes to a document.
- pub fn map(mut self, changes: &ChangeSet) -> Self {
- if changes.is_empty() {
- return self;
- }
- self = self.map_no_normalize(changes);
- // TODO: only normalize if needed (any ranges out of order)
- self = self.normalize();
-
- self
+ pub fn map(self, changes: &ChangeSet) -> Self {
+ self.map_no_normalize(changes).normalize()
}
/// Map selections over a set of changes. Useful for adjusting the selection position after
@@ -524,6 +517,9 @@ impl Selection {
/// Normalizes a `Selection`.
fn normalize(mut self) -> Self {
+ if self.len() < 2 {
+ return self;
+ }
let mut primary = self.ranges[self.primary_index];
self.ranges.sort_unstable_by_key(Range::from);
@@ -588,17 +584,12 @@ impl Selection {
assert!(!ranges.is_empty());
debug_assert!(primary_index < ranges.len());
- let mut selection = Self {
+ let selection = Self {
ranges,
primary_index,
};
- if selection.ranges.len() > 1 {
- // TODO: only normalize if needed (any ranges out of order)
- selection = selection.normalize();
- }
-
- selection
+ selection.normalize()
}
/// Takes a closure and maps each `Range` over the closure.