aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-11 07:14:52 +0000
committerBlaž Hrastnik2021-03-11 07:15:27 +0000
commit4acf30102282584e31d8ac9a7a69e45acbdd64ec (patch)
tree397163644e7adca237cf3309b942895ebc5fa4cb /helix-core
parent62c991230f511b2dc11f8d1701260511800429d4 (diff)
Implement the f/t/F/T find/till family of commands.
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/search.rs24
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)
}