diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 26d53c66e0..cfdac1b7f9 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -9983,6 +9983,10 @@ impl Editor { ) } + pub fn clear_search_within_ranges(&mut self, cx: &mut ViewContext) { + self.clear_background_highlights::(cx); + } + pub fn highlight_background( &mut self, ranges: &[Range], diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index cc783e6120..6d2a0c749b 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -353,7 +353,6 @@ fn replace_command( let range = snapshot .anchor_before(Point::new(range.start.saturating_sub(1) as u32, 0)) ..snapshot.anchor_before(Point::new(range.end as u32, 0)); - editor.set_search_within_ranges(&[range], cx) }) } @@ -394,9 +393,7 @@ fn replace_command( .timer(Duration::from_millis(200)) .await; editor - .update(&mut cx, |editor, cx| { - editor.set_search_within_ranges(&[], cx) - }) + .update(&mut cx, |editor, cx| editor.clear_search_within_ranges(cx)) .ok(); }) .detach(); @@ -512,6 +509,8 @@ fn parse_replace_all(query: &str) -> Replacement { #[cfg(test)] mod test { + use std::time::Duration; + use editor::{display_map::DisplayRow, DisplayPoint}; use indoc::indoc; use search::BufferSearchBar; @@ -744,5 +743,19 @@ mod test { a " }); + cx.executor().advance_clock(Duration::from_millis(250)); + cx.run_until_parked(); + + cx.simulate_shared_keystrokes("/ a enter").await; + cx.shared_state().await.assert_eq(indoc! { + "a + b + b + b + b + ˇa + a + " + }); } } diff --git a/crates/vim/test_data/test_replace_with_range.json b/crates/vim/test_data/test_replace_with_range.json index 46338719e9..8385af9a7f 100644 --- a/crates/vim/test_data/test_replace_with_range.json +++ b/crates/vim/test_data/test_replace_with_range.json @@ -10,3 +10,7 @@ {"Key":"b"} {"Key":"enter"} {"Get":{"state":"a\nb\nb\nb\nˇb\na\na\n ","mode":"Normal"}} +{"Key":"/"} +{"Key":"a"} +{"Key":"enter"} +{"Get":{"state":"a\nb\nb\nb\nb\nˇa\na\n ","mode":"Normal"}}