From b0311f4fc246f370bb317ab0b1fcb89823347caa Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 19 Jul 2021 09:25:10 -0700 Subject: Fixed primary cursor position calculation to use 1-width semantics. This had a bunch of knock-on effects that were buggy, such as bracket match highlighting. --- helix-core/src/selection.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'helix-core') diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index 21a6c108..7d2526b0 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -267,8 +267,15 @@ impl Selection { } #[must_use] - pub fn cursor(&self) -> usize { - self.primary().head + pub fn cursor(&self, text: RopeSlice) -> usize { + let range = self.primary(); + + // For 1-width cursor semantics. + if range.anchor < range.head { + prev_grapheme_boundary(text, range.head) + } else { + range.head + } } /// Ensure selection containing only the primary selection. -- cgit v1.2.3-70-g09d2