on master help sign in
fix: make find_prev_char and till_prev_char work

Bevore this PR `commands::find_prev_char` and `commands::till_prev_char` were triggerable through keys but `seach::find_nth_next()` was hardcoded in `_find_char`. The passed `fn` was nerver used. With this PR the passed `fn` is used. The change in search.rs resolves an off by one error in the behivor of `find_nth_prev`

commit444cd0b068f5a838caeeb7aa9c2d570fa330ce97 authorahkrr <alexhk@protonmail.com> dateSat 5 Jun 2021, 16:25 (5 years ago) parentf6a900f
2 files changed+5−4
helix-core/src/search.rs+3−2 helix-term/src/commands.rs+2−2
helix-core/src/search.rs+3−2
@@ -41,7 +41,8 @@ pub fn find_nth_prev(
4141 inclusive: bool,
4242) -> Option<usize> {
4343 // start searching right before pos
44− let mut chars = text.chars_at(pos.saturating_sub(1));
44+ pos = pos.saturating_sub(1);
45+ let mut chars = text.chars_at(pos);
4546
4647 for _ in 0..n {
4748 loop {
@@ -56,7 +57,7 @@ pub fn find_nth_prev(
5657 }
5758
5859 if !inclusive {
59− pos -= 1;
60+ pos += 1;
6061 }
6162
6263 Some(pos)
helix-term/src/commands.rs+2−2
@@ -315,7 +315,7 @@ fn _find_char<F>(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool)
315315where
316316 // TODO: make an options struct for and abstract this Fn into a searcher type
317317 // use the definition for w/b/e too
318− F: Fn(RopeSlice, char, usize, usize, bool) -> Option<usize>,
318+ F: Fn(RopeSlice, char, usize, usize, bool) -> Option<usize> + 'static,
319319{
320320 // TODO: count is reset to 1 before next key so we move it into the closure here.
321321 // Would be nice to carry over.
@@ -332,7 +332,7 @@ where
332332 let text = doc.text().slice(..);
333333
334334 let selection = doc.selection(view.id).transform(|mut range| {
335− search::find_nth_next(text, ch, range.head, count, inclusive).map_or(range, |pos| {
335+ search_fn(text, ch, range.head, count, inclusive).map_or(range, |pos| {
336336 if extend {
337337 Range::new(range.anchor, pos)
338338 } else {