aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/search.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/search.rs')
-rw-r--r--helix-core/src/search.rs38
1 files changed, 10 insertions, 28 deletions
diff --git a/helix-core/src/search.rs b/helix-core/src/search.rs
index 73be68c7..243ac227 100644
--- a/helix-core/src/search.rs
+++ b/helix-core/src/search.rs
@@ -1,18 +1,11 @@
use crate::RopeSlice;
-pub fn find_nth_next(
- text: RopeSlice,
- ch: char,
- mut pos: usize,
- n: usize,
- inclusive: bool,
-) -> Option<usize> {
- if pos >= text.len_chars() {
+pub fn find_nth_next(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Option<usize> {
+ if pos >= text.len_chars() || n == 0 {
return None;
}
- // start searching right after pos
- let mut chars = text.chars_at(pos + 1);
+ let mut chars = text.chars_at(pos);
for _ in 0..n {
loop {
@@ -26,28 +19,21 @@ pub fn find_nth_next(
}
}
- if !inclusive {
- pos -= 1;
- }
-
- Some(pos)
+ Some(pos - 1)
}
-pub fn find_nth_prev(
- text: RopeSlice,
- ch: char,
- mut pos: usize,
- n: usize,
- inclusive: bool,
-) -> Option<usize> {
- // start searching right before pos
+pub fn find_nth_prev(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Option<usize> {
+ if pos == 0 || n == 0 {
+ return None;
+ }
+
let mut chars = text.chars_at(pos);
for _ in 0..n {
loop {
let c = chars.prev()?;
- pos = pos.saturating_sub(1);
+ pos -= 1;
if c == ch {
break;
@@ -55,9 +41,5 @@ pub fn find_nth_prev(
}
}
- if !inclusive {
- pos += 1;
- }
-
Some(pos)
}