aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/movement.rs20
-rw-r--r--helix-core/src/search.rs4
2 files changed, 16 insertions, 8 deletions
diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs
index ba2e92b9..387b59b1 100644
--- a/helix-core/src/movement.rs
+++ b/helix-core/src/movement.rs
@@ -45,7 +45,7 @@ pub fn move_vertically(
let new_line = match dir {
Direction::Backward => row.saturating_sub(count),
- Direction::Forward => std::cmp::min(row.saturating_add(count), text.len_lines() - 1),
+ Direction::Forward => std::cmp::min(row.saturating_add(count), text.len_lines() - 2),
};
// convert to 0-indexed, subtract another 1 because len_chars() counts \n
@@ -76,8 +76,9 @@ pub fn move_next_word_start(slice: RopeSlice, mut begin: usize, count: usize) ->
begin += 1;
}
- // return if not skip while?
- skip_over_next(slice, &mut begin, |ch| ch == '\n');
+ if !skip_over_next(slice, &mut begin, |ch| ch == '\n') {
+ return None;
+ };
ch = slice.char(begin);
end = begin + 1;
@@ -134,7 +135,7 @@ pub fn move_next_word_end(slice: RopeSlice, mut begin: usize, count: usize) -> O
let mut end = begin;
for _ in 0..count {
- if begin + 1 == slice.len_chars() {
+ if begin + 2 >= slice.len_chars() {
return None;
}
@@ -145,8 +146,9 @@ pub fn move_next_word_end(slice: RopeSlice, mut begin: usize, count: usize) -> O
begin += 1;
}
- // return if not skip while?
- skip_over_next(slice, &mut begin, |ch| ch == '\n');
+ if !skip_over_next(slice, &mut begin, |ch| ch == '\n') {
+ return None;
+ };
end = begin;
@@ -199,18 +201,20 @@ fn categorize(ch: char) -> Category {
}
#[inline]
-pub fn skip_over_next<F>(slice: RopeSlice, pos: &mut usize, fun: F)
+/// Returns true if there are more characters left after the new position.
+pub fn skip_over_next<F>(slice: RopeSlice, pos: &mut usize, fun: F) -> bool
where
F: Fn(char) -> bool,
{
let mut chars = slice.chars_at(*pos);
- for ch in chars {
+ while let Some(ch) = chars.next() {
if !fun(ch) {
break;
}
*pos += 1;
}
+ chars.next().is_some()
}
#[inline]
diff --git a/helix-core/src/search.rs b/helix-core/src/search.rs
index af754ab7..55f7bf1d 100644
--- a/helix-core/src/search.rs
+++ b/helix-core/src/search.rs
@@ -7,6 +7,10 @@ pub fn find_nth_next(
n: usize,
inclusive: bool,
) -> Option<usize> {
+ if pos >= text.len_chars() {
+ return None;
+ }
+
// start searching right after pos
let mut chars = text.chars_at(pos + 1);