aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/search.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-07-29 09:43:20 +0000
committerGitHub2021-07-29 09:43:20 +0000
commit05d20e196f81c8b71c2aecaf46f5d443d6b6b582 (patch)
tree0642d43c12f16ac3c68c19602c64fdea8108cc97 /helix-core/src/search.rs
parent8a2fa692f26f5bff5861151f395304837f5d93ec (diff)
parente4d41d06e3b52863d35ce3703f78cc8e0807c504 (diff)
Merge pull request #376 from cessen/great_line_ending_and_cursor_range_cleanup
The Great Line Ending & Cursor Range Cleanup
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)
}