aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/selection.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-06-30 14:45:15 +0000
committerNathan Vegdahl2021-07-01 21:22:28 +0000
commit7c7be6d58326725954be7bd16fa3ff5e84610c17 (patch)
tree9bff2a3e27a732f5e2fc53e0f951e0dc08712c3c /helix-core/src/selection.rs
parent0ae522f3df433bb778fa2ff98fd3d7047021c6ef (diff)
Make `Selection`'s normalize and transform methods self-consuming only.
Diffstat (limited to 'helix-core/src/selection.rs')
-rw-r--r--helix-core/src/selection.rs25
1 files changed, 4 insertions, 21 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index ebc88f8b..f3119a59 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -261,7 +261,7 @@ impl Selection {
pub fn push(mut self, range: Range) -> Self {
self.ranges.push(range);
- self.normalized()
+ self.normalize()
}
// replace_range
@@ -308,7 +308,7 @@ impl Selection {
}
/// Normalizes a `Selection`.
- pub fn normalize(&mut self) -> &mut Self {
+ pub fn normalize(mut self) -> Self {
let primary = self.ranges[self.primary_index];
self.ranges.sort_unstable_by_key(Range::from);
self.primary_index = self
@@ -335,13 +335,6 @@ impl Selection {
self
}
- /// Normalizes a `Selection`.
- #[must_use]
- pub fn normalized(mut self) -> Self {
- self.normalize();
- self
- }
-
// TODO: consume an iterator or a vec to reduce allocations?
#[must_use]
pub fn new(ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Self {
@@ -355,14 +348,14 @@ impl Selection {
if selection.ranges.len() > 1 {
// TODO: only normalize if needed (any ranges out of order)
- selection.normalize();
+ selection = selection.normalize();
}
selection
}
/// Takes a closure and maps each `Range` over the closure.
- pub fn transform<F>(&mut self, f: F) -> &mut Self
+ pub fn transform<F>(mut self, f: F) -> Self
where
F: Fn(Range) -> Range,
{
@@ -373,16 +366,6 @@ impl Selection {
self
}
- /// Takes a closure and maps each `Range` over the closure.
- #[must_use]
- pub fn transformed<F>(mut self, f: F) -> Self
- where
- F: Fn(Range) -> Range,
- {
- self.transform(f);
- self
- }
-
pub fn fragments<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator<Item = Cow<str>> + 'a {
self.ranges.iter().map(move |range| range.fragment(text))
}