Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

vim: Fix n/N and */# selecting text after cmd+f search (#54027)

Liber068d64edd637
diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs
index 1ebf51aa293..92baae1d37f 100644
--- a/crates/vim/src/normal/search.rs
+++ b/crates/vim/src/normal/search.rs
@@ -389,6 +389,15 @@ impl Vim {
};
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
+
+ if self.search.cmd_f_search {
+ self.search.cmd_f_search = false;
+ if self.mode.is_visual() {
+ self.switch_mode(Mode::Normal, false, window, cx);
+ }
+ self.sync_vim_settings(window, cx);
+ }
+
let prior_selections = self.editor_selections(window, cx);
let success = pane.update(cx, |pane, cx| {
@@ -433,6 +442,15 @@ impl Vim {
};
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
+
+ if self.search.cmd_f_search {
+ self.search.cmd_f_search = false;
+ if self.mode.is_visual() {
+ self.switch_mode(Mode::Normal, false, window, cx);
+ }
+ self.sync_vim_settings(window, cx);
+ }
+
let prior_selections = self.editor_selections(window, cx);
let vim = cx.entity();
@@ -1017,6 +1035,46 @@ mod test {
cx.assert_state("one «oneˇ» one one", Mode::Insert);
}
+ #[gpui::test]
+ async fn test_n_after_cmd_f_search(cx: &mut gpui::TestAppContext) {
+ let mut cx = VimTestContext::new(cx, true).await;
+ cx.set_state("ˇone two one two one", Mode::Normal);
+ cx.run_until_parked();
+
+ // Use cmd+f to search (non-vim style)
+ cx.simulate_keystrokes("cmd-f");
+ cx.run_until_parked();
+ cx.simulate_keystrokes("escape");
+ cx.run_until_parked();
+
+ // Now use n to go to next match — should move cursor, not create selection
+ cx.simulate_keystrokes("n");
+ cx.run_until_parked();
+ cx.assert_state("one two ˇone two one", Mode::Normal);
+
+ cx.simulate_keystrokes("n");
+ cx.run_until_parked();
+ cx.assert_state("one two one two ˇone", Mode::Normal);
+ }
+
+ #[gpui::test]
+ async fn test_star_after_cmd_f_search(cx: &mut gpui::TestAppContext) {
+ let mut cx = VimTestContext::new(cx, true).await;
+ cx.set_state("ˇone two one two one", Mode::Normal);
+ cx.run_until_parked();
+
+ // Use cmd+f to search (non-vim style)
+ cx.simulate_keystrokes("cmd-f");
+ cx.run_until_parked();
+ cx.simulate_keystrokes("escape");
+ cx.run_until_parked();
+
+ // Now use * to search under cursor — should move cursor, not create selection
+ cx.simulate_keystrokes("*");
+ cx.run_until_parked();
+ cx.assert_state("one two ˇone two one", Mode::Normal);
+ }
+
#[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/visual.rs b/crates/vim/src/visual.rs
index bc53167b158..077e098bb3a 100644
--- a/crates/vim/src/visual.rs
+++ b/crates/vim/src/visual.rs
@@ -897,6 +897,9 @@ impl Vim {
}
});
if !match_exists {
+ self.update_editor(cx, |_, editor, _| {
+ editor.set_collapse_matches(true);
+ });
self.clear_operator(window, cx);
self.stop_replaying(cx);
return;