aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-19 16:25:10 +0000
committerNathan Vegdahl2021-07-19 16:25:10 +0000
commitb0311f4fc246f370bb317ab0b1fcb89823347caa (patch)
tree7bb7f6783cdba83d784af2bcbd780e57a32c715c /helix-core/src
parent079d4ed86df30c78ca00fd4b86f906c3ea9df7db (diff)
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.
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/selection.rs11
1 files changed, 9 insertions, 2 deletions
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.