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.

Add `;` key binding for Helix mode (#34315)

Daniel Saublec1307cead48b
diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.json
index dcb52e52503..89a71e59e6a 100644
--- a/assets/keymaps/vim.json
+++ b/assets/keymaps/vim.json
@@ -377,6 +377,7 @@
"context": "vim_mode == helix_normal && !menu",
"bindings": {
"ctrl-[": "editor::Cancel",
+ ";": "vim::HelixCollapseSelection",
":": "command_palette::Toggle",
"left": "vim::WrappingLeft",
"right": "vim::WrappingRight",
diff --git a/crates/vim/src/normal.rs b/crates/vim/src/normal.rs
index 6131032f4fa..13128e7b403 100644
--- a/crates/vim/src/normal.rs
+++ b/crates/vim/src/normal.rs
@@ -64,6 +64,8 @@ actions!(
DeleteRight,
/// Deletes using Helix-style behavior.
HelixDelete,
+ /// Collapse the current selection
+ HelixCollapseSelection,
/// Changes from cursor to end of line.
ChangeToEndOfLine,
/// Deletes from cursor to end of line.
@@ -143,6 +145,20 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
vim.switch_mode(Mode::HelixNormal, true, window, cx);
});
+ Vim::action(editor, cx, |vim, _: &HelixCollapseSelection, window, cx| {
+ vim.update_editor(window, cx, |_, editor, window, cx| {
+ editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
+ s.move_with(|map, selection| {
+ let mut point = selection.head();
+ if !selection.reversed && !selection.is_empty() {
+ point = movement::left(map, selection.head());
+ }
+ selection.collapse_to(point, selection.goal)
+ });
+ });
+ });
+ });
+
Vim::action(editor, cx, |vim, _: &ChangeToEndOfLine, window, cx| {
vim.start_recording(cx);
let times = Vim::take_count(cx);