diff options
author | Nathan Vegdahl | 2021-07-08 23:45:19 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-08 23:47:20 +0000 |
commit | b4c59b444cc4963f95a95fe10f166e58ef857288 (patch) | |
tree | 7702d19b657345dbb937363120a7e22648136c58 /helix-core/src/search.rs | |
parent | 753f7f381b96f591be3c0e37a93b90776c5405cb (diff) |
Update surround commands to work with gap indexing.
Diffstat (limited to 'helix-core/src/search.rs')
-rw-r--r-- | helix-core/src/search.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/helix-core/src/search.rs b/helix-core/src/search.rs index 73be68c7..d4eb11a9 100644 --- a/helix-core/src/search.rs +++ b/helix-core/src/search.rs @@ -7,12 +7,11 @@ pub fn find_nth_next( n: usize, inclusive: bool, ) -> Option<usize> { - if pos >= text.len_chars() { + if pos >= text.len_chars() || n == 0 { return None; } - // start searching right after pos - let mut chars = text.chars_at(pos + 1); + let mut chars = text.chars_at(pos); for _ in 0..n { loop { @@ -40,14 +39,17 @@ pub fn find_nth_prev( n: usize, inclusive: bool, ) -> Option<usize> { - // start searching right before pos + if pos == 0 || n == 0 { + return None; + } + let mut chars = text.chars_at(pos); for _ in 0..n { loop { let c = chars.prev()?; - pos = pos.saturating_sub(1); + pos -= 1; if c == ch { break; |