diff options
author | Blaž Hrastnik | 2020-09-07 08:08:28 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-09-07 08:08:28 +0000 |
commit | dd749bb2846584aa20078cfa2aea4fe18678c12c (patch) | |
tree | 8ae7048e4247a9f11087230dabe16c4b45914a85 /helix-core/src/selection.rs | |
parent | 4e349add60db745ebf459bb97b77031d3d9b6678 (diff) |
Expand transaction API.
Diffstat (limited to 'helix-core/src/selection.rs')
-rw-r--r-- | helix-core/src/selection.rs | 17 |
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 |