Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Change behavior of search with vim mode enabled (#51073)
Vivek Jain0b275eaa44c8
diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rsindex c1e766c03a8..d2c8f4b78dc 100644--- a/crates/vim/src/helix.rs+++ b/crates/vim/src/helix.rs@@ -648,6 +648,7 @@ impl Vim {self.search = SearchState {direction: searchable::Direction::Next,count: 1,+ cmd_f_search: false,prior_selections,prior_operator: self.operator_stack.last().cloned(),prior_mode: self.mode,diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rsindex 248f43c0819..6a8394f4471 100644--- a/crates/vim/src/normal/search.rs+++ b/crates/vim/src/normal/search.rs@@ -284,6 +284,7 @@ impl Vim {self.search = SearchState {direction,count,+ cmd_f_search: false,prior_selections,prior_operator: self.operator_stack.last().cloned(),prior_mode,@@ -298,6 +299,7 @@ impl Vim {let current_mode = self.mode;self.search = Default::default();self.search.prior_mode = current_mode;+ self.search.cmd_f_search = true;cx.propagate();}@@ -957,6 +959,45 @@ mod test {cx.assert_editor_state("«oneˇ» one one one");}+ #[gpui::test]+ async fn test_non_vim_search_in_vim_mode(cx: &mut gpui::TestAppContext) {+ let mut cx = VimTestContext::new(cx, true).await;+ cx.cx.set_state("ˇone one one one");+ cx.run_until_parked();+ cx.simulate_keystrokes("cmd-f");+ cx.run_until_parked();++ cx.assert_state("«oneˇ» one one one", Mode::Visual);+ cx.simulate_keystrokes("enter");+ cx.run_until_parked();+ cx.assert_state("one «oneˇ» one one", Mode::Visual);+ cx.simulate_keystrokes("shift-enter");+ cx.run_until_parked();+ cx.assert_state("«oneˇ» one one one", Mode::Visual);++ cx.simulate_keystrokes("escape");+ cx.run_until_parked();+ cx.assert_state("«oneˇ» one one one", Mode::Visual);+ }++ #[gpui::test]+ async fn test_non_vim_search_in_vim_insert_mode(cx: &mut gpui::TestAppContext) {+ let mut cx = VimTestContext::new(cx, true).await;+ cx.set_state("ˇone one one one", Mode::Insert);+ cx.run_until_parked();+ cx.simulate_keystrokes("cmd-f");+ cx.run_until_parked();++ cx.assert_state("«oneˇ» one one one", Mode::Insert);+ cx.simulate_keystrokes("enter");+ cx.run_until_parked();+ cx.assert_state("one «oneˇ» one one", Mode::Insert);++ cx.simulate_keystrokes("escape");+ cx.run_until_parked();+ cx.assert_state("one «oneˇ» one one", Mode::Insert);+ }+#[gpui::test]async fn test_visual_star_hash(cx: &mut gpui::TestAppContext) {let mut cx = NeovimBackedTestContext::new(cx).await;diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rsindex 2ae4abe33a0..2fa5382c542 100644--- a/crates/vim/src/state.rs+++ b/crates/vim/src/state.rs@@ -1022,6 +1022,7 @@ impl Clone for ReplayableAction {pub struct SearchState {pub direction: Direction,pub count: usize,+ pub cmd_f_search: bool,pub prior_selections: Vec<Range<Anchor>>,pub prior_operator: Option<Operator>,diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rsindex 05046899b61..6e1849340f1 100644--- a/crates/vim/src/vim.rs+++ b/crates/vim/src/vim.rs@@ -432,8 +432,12 @@ pub fn init(cx: &mut App) {.and_then(|item| item.act_as::<Editor>(cx)).and_then(|editor| editor.read(cx).addon::<VimAddon>().cloned());let Some(vim) = vim else { return };- vim.entity.update(cx, |_, cx| {- cx.defer_in(window, |vim, window, cx| vim.search_submit(window, cx))+ vim.entity.update(cx, |vim, cx| {+ if !vim.search.cmd_f_search {+ cx.defer_in(window, |vim, window, cx| vim.search_submit(window, cx))+ } else {+ cx.propagate()+ }})});workspace.register_action(|_, _: &GoToTab, window, cx| {@@ -2086,7 +2090,7 @@ impl Vim {VimEditorSettingsState {cursor_shape: self.cursor_shape(cx),clip_at_line_ends: self.clip_at_line_ends(),- collapse_matches: !HelixModeSetting::get_global(cx).0,+ collapse_matches: !HelixModeSetting::get_global(cx).0 && !self.search.cmd_f_search,input_enabled: self.editor_input_enabled(),expects_character_input: self.expects_character_input(),autoindent: self.should_autoindent(),