summaryrefslogtreecommitdiff
path: root/helix-core/src/state.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-11 01:44:38 +0000
committerBlaž Hrastnik2021-03-11 01:44:38 +0000
commit62c991230f511b2dc11f8d1701260511800429d4 (patch)
tree0cb7cc0102134a973c5f600e61bca350ad39d74d /helix-core/src/state.rs
parent90f9cd6d6275048db664afa4139e7f2bdfaeacb0 (diff)
find-till (f) prototype, on_next_key mode implementation.
Diffstat (limited to 'helix-core/src/state.rs')
-rw-r--r--helix-core/src/state.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/helix-core/src/state.rs b/helix-core/src/state.rs
index d2ebca47..8ff86f0c 100644
--- a/helix-core/src/state.rs
+++ b/helix-core/src/state.rs
@@ -123,6 +123,8 @@ impl State {
pub fn move_next_word_start(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
// TODO: confirm it's fine without using graphemes, I think it should be
for _ in 0..count {
+ // TODO: if end return end
+
let ch = slice.char(pos);
let next = slice.char(pos.saturating_add(1));
if categorize(ch) != categorize(next) {
@@ -148,8 +150,12 @@ impl State {
pub fn move_prev_word_start(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
// TODO: confirm it's fine without using graphemes, I think it should be
for _ in 0..count {
+ if pos == 0 {
+ return pos;
+ }
+
let ch = slice.char(pos);
- let prev = slice.char(pos.saturating_sub(1)); // TODO: just return original pos if at start
+ let prev = slice.char(pos - 1);
if categorize(ch) != categorize(prev) {
pos -= 1;
@@ -176,6 +182,8 @@ impl State {
pub fn move_next_word_end(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
for _ in 0..count {
+ // TODO: if end return end
+
// TODO: confirm it's fine without using graphemes, I think it should be
let ch = slice.char(pos);
let next = slice.char(pos.saturating_add(1));
@@ -303,7 +311,7 @@ where
if !fun(ch) {
break;
}
- *pos += 1;
+ *pos += 1; // TODO: can go 1 over end of doc
}
}
@@ -319,7 +327,7 @@ where
if !fun(ch) {
break;
}
- *pos -= 1;
+ *pos -= pos.saturating_sub(1);
}
}