aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/selection.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-24 14:44:11 +0000
committerNathan Vegdahl2021-07-24 14:44:11 +0000
commitf96b8b769b3c7457935b5c02db870af97036f7b6 (patch)
treea730fd2e970d6349e0f11b450f1e58b2c79d010b /helix-core/src/selection.rs
parent20723495d3ee82047bc7584e9eca1424d1256f4c (diff)
Switch to a cleaner range-head moving abstraction.
Also fix a bunch of bugs related to it.
Diffstat (limited to 'helix-core/src/selection.rs')
-rw-r--r--helix-core/src/selection.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index e40fceb1..cef68212 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -248,18 +248,18 @@ impl Range {
}
}
- /// Moves the `Range` to `char_idx`. If `extend == true`, then only the head
- /// is moved to `char_idx`, and the anchor is adjusted only as needed to
- /// preserve 1-width range semantics.
+ /// Moves the head of the `Range` to `char_idx`, adjusting the anchor
+ /// as needed to preserve 1-width range semantics.
+ ///
+ /// `block_cursor` specifies whether it should treat `char_idx` as a block
+ /// cursor position or as a range-end position.
///
/// This method assumes that the range and `char_idx` are already properly
/// grapheme-aligned.
#[must_use]
#[inline]
- pub fn put(self, text: RopeSlice, char_idx: usize, extend: bool) -> Range {
- let anchor = if !extend {
- char_idx
- } else if self.head >= self.anchor && char_idx < self.anchor {
+ pub fn move_head(self, text: RopeSlice, char_idx: usize, block_cursor: bool) -> Range {
+ let anchor = if self.head >= self.anchor && char_idx < self.anchor {
next_grapheme_boundary(text, self.anchor)
} else if self.head < self.anchor && char_idx >= self.anchor {
prev_grapheme_boundary(text, self.anchor)
@@ -267,7 +267,11 @@ impl Range {
self.anchor
};
- Range::new(anchor, char_idx)
+ if block_cursor && anchor <= char_idx {
+ Range::new(anchor, next_grapheme_boundary(text, char_idx))
+ } else {
+ Range::new(anchor, char_idx)
+ }
}
// groupAt