aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/selection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/selection.rs')
-rw-r--r--helix-core/src/selection.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index 1c0b6b74..a196417a 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -113,6 +113,11 @@ impl Selection {
self.ranges[self.primary_index]
}
+ #[must_use]
+ pub fn cursor(&self) -> usize {
+ self.primary().head
+ }
+
/// Ensure selection containing only the primary selection.
pub fn into_single(self) -> Self {
if self.ranges.len() == 1 {
@@ -144,6 +149,10 @@ impl Selection {
)
}
+ pub fn ranges(&self) -> &[Range] {
+ &self.ranges
+ }
+
#[must_use]
/// Constructs a selection holding a single range.
pub fn single(anchor: usize, head: usize) -> Self {
@@ -200,6 +209,14 @@ impl Selection {
// TODO: only normalize if needed (any ranges out of order)
normalize(ranges, primary_index)
}
+
+ /// Takes a closure and maps each selection over the closure.
+ pub fn transform<F>(self, f: F) -> Self
+ where
+ F: Fn(Range) -> Range,
+ {
+ Self::new(self.ranges.into_iter().map(f).collect(), self.primary_index)
+ }
}
// TODO: checkSelection -> check if valid for doc length