aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-23 21:27:12 +0000
committerNathan Vegdahl2021-07-23 21:27:12 +0000
commitad814b8c2eba229e99524f412077315dd1d24127 (patch)
treec2949f8e79edd3b185651607dcc9567cc08527d1 /helix-core/src
parentffb8057a7fcd65b5caaa1e86b66c6f6e0fb5270f (diff)
Fix append mode, and make insertion always happen at head of range.
Diffstat (limited to 'helix-core/src')
-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))
}