aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorantoyo2022-04-01 13:14:37 +0000
committerGitHub2022-04-01 13:14:37 +0000
commit47fe7397574208ecdcccc63770ce1b0374de1126 (patch)
tree41a9186280d79aa8fd77ace87c09eb136f173f0a /helix-core/src
parent855e438f55cb278de8203ac4911561c4c7ad656c (diff)
Jump to the next number on the line before incrementing (#1778)
* Jump to the next number on the line before incrementing Partially fix #1645 * Refactor to avoid duplicating find_nth_next
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/search.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/helix-core/src/search.rs b/helix-core/src/search.rs
index 243ac227..81cb4129 100644
--- a/helix-core/src/search.rs
+++ b/helix-core/src/search.rs
@@ -1,6 +1,28 @@
use crate::RopeSlice;
-pub fn find_nth_next(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Option<usize> {
+// TODO: switch to std::str::Pattern when it is stable.
+pub trait CharMatcher {
+ fn char_match(&self, ch: char) -> bool;
+}
+
+impl CharMatcher for char {
+ fn char_match(&self, ch: char) -> bool {
+ *self == ch
+ }
+}
+
+impl<F: Fn(&char) -> bool> CharMatcher for F {
+ fn char_match(&self, ch: char) -> bool {
+ (*self)(&ch)
+ }
+}
+
+pub fn find_nth_next<M: CharMatcher>(
+ text: RopeSlice,
+ char_matcher: M,
+ mut pos: usize,
+ n: usize,
+) -> Option<usize> {
if pos >= text.len_chars() || n == 0 {
return None;
}
@@ -13,7 +35,7 @@ pub fn find_nth_next(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Opt
pos += 1;
- if c == ch {
+ if char_matcher.char_match(c) {
break;
}
}