From 62c991230f511b2dc11f8d1701260511800429d4 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 11 Mar 2021 10:44:38 +0900 Subject: find-till (f) prototype, on_next_key mode implementation. --- helix-core/src/state.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'helix-core/src/state.rs') 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); } } -- cgit v1.2.3-70-g09d2