From 4acf30102282584e31d8ac9a7a69e45acbdd64ec Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 11 Mar 2021 16:14:52 +0900 Subject: Implement the f/t/F/T find/till family of commands. --- helix-core/src/search.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'helix-core/src') 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 { +pub fn find_nth_next( + text: RopeSlice, + ch: char, + mut pos: usize, + n: usize, + inclusive: bool, +) -> Option { // 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 { +pub fn find_nth_prev( + text: RopeSlice, + ch: char, + mut pos: usize, + n: usize, + inclusive: bool, +) -> Option { // 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) } -- cgit v1.2.3-70-g09d2