diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rs index c1e766c03a897facb3c7acf76b3ef7811e6910a8..d2c8f4b78dcde8c4f2135b63ee3d07f04e01ebd5 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.rs index 248f43c08192182cb266dbfc43a5a769f87429cd..6a8394f44710b7e241b7ba38f4913899a5afbce6 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.rs index 2ae4abe33a0fbb4bc6f8a838e60dc0857949e0dc..2fa5382c542999b8d3cb53ea85bed4c99257a3ea 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>, pub prior_operator: Option, diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 05046899b6164f7c5884e3ad64ad69caaeb2015f..6e1849340f17b776a34546dd9a118dc55e8dab84 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::(cx)) .and_then(|editor| editor.read(cx).addon::().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(),