diff options
Diffstat (limited to 'helix-core/src/search.rs')
-rw-r--r-- | helix-core/src/search.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/helix-core/src/search.rs b/helix-core/src/search.rs index c03f60df..af754ab7 100644 --- a/helix-core/src/search.rs +++ b/helix-core/src/search.rs @@ -1,6 +1,12 @@ use crate::RopeSlice; -pub fn find_nth_next(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Option<usize> { +pub fn find_nth_next( + text: RopeSlice, + ch: char, + mut pos: usize, + n: usize, + inclusive: bool, +) -> Option<usize> { // start searching right after pos let mut chars = text.chars_at(pos + 1); @@ -16,10 +22,20 @@ pub fn find_nth_next(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Opt } } + if !inclusive { + pos -= 1; + } + Some(pos) } -pub fn find_nth_prev(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Option<usize> { +pub fn find_nth_prev( + text: RopeSlice, + ch: char, + mut pos: usize, + n: usize, + inclusive: bool, +) -> Option<usize> { // start searching right before pos let mut chars = text.chars_at(pos.saturating_sub(1)); @@ -35,5 +51,9 @@ pub fn find_nth_prev(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Opt } } + if !inclusive { + pos -= 1; + } + Some(pos) } |