summaryrefslogtreecommitdiff
path: root/helix-core/src/textobject.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-26 15:40:30 +0000
committerNathan Vegdahl2021-07-26 15:40:30 +0000
commit0883b4fae03343978e61fc377775d7ba93f86b40 (patch)
tree1a3d6fe100b39a2cae88842017e441aa3e96707a /helix-core/src/textobject.rs
parentf96b8b769b3c7457935b5c02db870af97036f7b6 (diff)
Collect some common patterns into methods on `Range`.
Diffstat (limited to 'helix-core/src/textobject.rs')
-rw-r--r--helix-core/src/textobject.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/helix-core/src/textobject.rs b/helix-core/src/textobject.rs
index ae18d7cf..e011c912 100644
--- a/helix-core/src/textobject.rs
+++ b/helix-core/src/textobject.rs
@@ -59,17 +59,12 @@ pub fn textobject_word(
textobject: TextObject,
_count: usize,
) -> Range {
- // For 1-width cursor semantics.
- let head = if range.head > range.anchor {
- prev_grapheme_boundary(slice, range.head)
- } else {
- range.head
- };
+ let pos = range.cursor(slice);
- let word_start = find_word_boundary(slice, head, Direction::Backward);
- let word_end = match slice.get_char(head).map(categorize_char) {
- None | Some(CharCategory::Whitespace | CharCategory::Eol) => head,
- _ => find_word_boundary(slice, head + 1, Direction::Forward),
+ let word_start = find_word_boundary(slice, pos, Direction::Backward);
+ let word_end = match slice.get_char(pos).map(categorize_char) {
+ None | Some(CharCategory::Whitespace | CharCategory::Eol) => pos,
+ _ => find_word_boundary(slice, pos + 1, Direction::Forward),
};
// Special case.