Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Improve helix keymap (#59638)
Jason Williamsae0f4462ae3d
diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.jsonindex d23fb2d589d..0258f34758e 100644--- a/assets/keymaps/vim.json+++ b/assets/keymaps/vim.json@@ -454,6 +454,8 @@"shift-t": ["vim::PushFindBackward", { "after": true, "multiline": true }],"shift-f": ["vim::PushFindBackward", { "after": false, "multiline": true }],"alt-.": "vim::RepeatFind",+ "alt-b": "editor::MoveToStartOfLargerSyntaxNode",+ "alt-e": "editor::MoveToEndOfLargerSyntaxNode",// Changes"shift-r": "editor::Paste",@@ -483,6 +485,7 @@"alt-shift-c": "vim::HelixDuplicateAbove","%": "editor::SelectAll","x": "vim::HelixSelectLine",+ "*": "buffer_search::UseSelectionForFind","shift-x": "editor::SelectLine","ctrl-c": "editor::ToggleComments","alt-o": "editor::SelectLargerSyntaxNode",@@ -688,7 +691,8 @@"shift-b": "pane::ActivateLastItem","x": "editor::SelectSmallerSyntaxNode","d": "editor::GoToDiagnostic",- "c": "editor::GoToHunk",+ "c": "vim::NextComment",+ "g": "editor::GoToHunk","space": "vim::InsertEmptyLineBelow",},},@@ -706,7 +710,8 @@"shift-b": ["pane::ActivateItem", 0],"x": "editor::SelectLargerSyntaxNode","d": "editor::GoToPreviousDiagnostic",- "c": "editor::GoToPreviousHunk",+ "c": "vim::PreviousComment",+ "g": "editor::GoToPreviousHunk","space": "vim::InsertEmptyLineAbove",},},diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rsindex d3ff4fa05cb..092db5fe754 100644--- a/crates/vim/src/helix.rs+++ b/crates/vim/src/helix.rs@@ -4240,4 +4240,68 @@ mod test {Mode::HelixSelect,);}++ #[gpui::test]+ async fn test_helix_go_to_hunk(cx: &mut gpui::TestAppContext) {+ let mut cx = VimTestContext::new(cx, true).await;+ cx.enable_helix();++ cx.set_state(+ indoc! {"+ ˇone+ two+ three"},+ Mode::HelixNormal,+ );+ cx.set_head_text(indoc! {"+ one+ CHANGED+ three"});+ cx.run_until_parked();++ cx.simulate_keystrokes("]");+ assert_eq!(+ cx.active_operator(),+ Some(Operator::HelixNext { around: true })+ );++ cx.simulate_keystrokes("g");+ cx.assert_state(+ indoc! {"+ one+ ˇtwo+ three"},+ Mode::HelixNormal,+ );+ assert_eq!(cx.active_operator(), None);++ cx.set_state(+ indoc! {"+ one+ two+ ˇthree"},+ Mode::HelixNormal,+ );+ cx.set_head_text(indoc! {"+ one+ CHANGED+ three"});+ cx.run_until_parked();++ cx.simulate_keystrokes("[");+ assert_eq!(+ cx.active_operator(),+ Some(Operator::HelixPrevious { around: true })+ );++ cx.simulate_keystrokes("g");+ cx.assert_state(+ indoc! {"+ one+ ˇtwo+ three"},+ Mode::HelixNormal,+ );+ assert_eq!(cx.active_operator(), None);+ }}diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rsindex e956e585687..d58ad3a2c65 100644--- a/crates/vim/src/vim.rs+++ b/crates/vim/src/vim.rs@@ -1469,6 +1469,22 @@ impl Vim {} else {mode = "waiting".to_string();}+ } else if matches!(+ active_operator,+ Operator::HelixNext { .. } | Operator::HelixPrevious { .. }+ ) {+ // Helix `[`/`]` take a curated, keymap-dispatched selector key+ // rather than a motion over a range, so they keep `operator_id`+ // set (so `vim_operator == helix_next/previous` context must+ // resolve) but must not use the `operator` mode, as that adds+ // `VimControl` and the `vim_mode == operator` context, whose `g+ // ...` bindings would make a single-key follow-up like `g` a+ // multi-key prefix and leave `] g` waiting for more input.+ // Setting the mode to `waiting` carries none of those+ // conflicting bindings and still provides bindings for+ // `escape`/`ctrl-c` to `ClearOperators`.+ operator_id = active_operator.id();+ mode = "waiting".to_string();} else {operator_id = active_operator.id();mode = "operator".to_string();