From 2b0e3ee7b17d205e04b3efd8fd7b0862d7d9f1cd Mon Sep 17 00:00:00 2001 From: Innes Anderson-Morrison Date: Tue, 17 Sep 2024 18:13:45 +0100 Subject: [PATCH] fix(ad): correcting the behaviour of find_forward for Buffers --- src/buffer/mod.rs | 4 ++++ src/dot/find.rs | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 021aae6..6e8ac80 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -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; } } diff --git a/src/dot/find.rs b/src/dot/find.rs index 468e862..5e94327 100644 --- a/src/dot/find.rs +++ b/src/dot/find.rs @@ -154,7 +154,7 @@ impl<'a> Find for &'a str { } if cix == last { - return Some((start, i + 1)); + return Some((start, i)); } cix += 1; @@ -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); + } +}