Skip to content

Commit

Permalink
fix(ad): correcting the behaviour of find_forward for Buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Sep 17, 2024
1 parent 624fd28 commit 2b0e3ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,10 @@ impl Buffer {

pub(crate) fn find_forward(&mut self, s: &str) {
if let Some(dot) = find_forward_wrapping(&s, self) {
for (from, to) in [self.dot.as_char_indices(), dot.as_char_indices()] {
self.clear_render_cache_between_indices(from, to);
}

self.dot = dot;
}
}
Expand Down
22 changes: 21 additions & 1 deletion src/dot/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'a> Find for &'a str {
}

if cix == last {
return Some((start, i + 1));
return Some((start, i));
}

cix += 1;
Expand Down Expand Up @@ -183,3 +183,23 @@ impl Find for String {
self.chars().rev().collect()
}
}

#[cfg(test)]
mod tests {
use super::*;
use simple_test_case::test_case;

#[test_case("this"; "first word")]
#[test_case("is"; "inner word two chars")]
#[test_case("a"; "inner word single char")]
#[test_case("find"; "inner word multiple chars")]
#[test_case("test"; "last word")]
#[test]
fn find_forward_str(s: &str) {
let b = Buffer::new_virtual(0, "test", "this is a find test");
let dot = find_forward_wrapping(&s, &b).expect("to find string");
let matched_text = dot.content(&b);

assert_eq!(matched_text, s);
}
}

0 comments on commit 2b0e3ee

Please sign in to comment.