From ad814b8c2eba229e99524f412077315dd1d24127 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Fri, 23 Jul 2021 14:27:12 -0700 Subject: Fix append mode, and make insertion always happen at head of range. --- helix-core/src/selection.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'helix-core') 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> + 'a { self.ranges.iter().map(move |range| range.fragment(text)) } -- cgit v1.2.3-70-g09d2