aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/selection.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index 6ca52ebf..e40fceb1 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -447,6 +447,20 @@ impl Selection {
self.transform(|r| r.min_width_1(text))
}
+ /// Transforms the selection into all of the left-side head positions,
+ /// using 1-width semantics.
+ pub fn cursors(self, text: RopeSlice) -> Self {
+ self.transform(|range| {
+ // For 1-width cursor semantics.
+ let pos = if range.anchor < range.head {
+ prev_grapheme_boundary(text, range.head).max(range.anchor)
+ } else {
+ range.head
+ };
+ Range::new(pos, pos)
+ })
+ }
+
pub fn fragments<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator<Item = Cow<str>> + 'a {
self.ranges.iter().map(move |range| range.fragment(text))
}