# Objective - Fixes: https://github.com/zed-industries/zed/issues/60738 - Re-iteration of https://github.com/zed-industries/zed/pull/63918 with suggested changes ## Solution - Added the parameter `comment_empty_lines` to `editor::ToggleComments` set to `false` by default. ## Testing - Tested manually. See showcase below. - Added two automated tests for the added feature. - Tested on MacOS. ## Self-Review Checklist: - [X] I've reviewed my own diff for quality, security, and reliability - [X] Unsafe blocks (if any) have justifying comments - [X] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [X] Tests cover the new/changed behavior - [X] Performance impact has been considered and is acceptable ## References The action's behavior was observed across Emacs, VSCode, and Intellij, and the corresponding keymaps were set accordingly. https://github.com/user-attachments/assets/36c1a27a-357c-468a-b56b-59ef31265329 https://github.com/user-attachments/assets/de755753-9de1-4771-980f-177810fb85ef https://github.com/user-attachments/assets/c8ecd261-2bba-4345-89f4-c1d708d8b6d2 ## Showcase Below is the screen recording of these three tests: 1. Behavior of toggling comments when `comment_empty_lines` is `true`. 2. Switching the parameter value to true after commenting a block and un-commenting the same block does not re-comment the block due to an empty line in between. 3. Menu bar item is still present, albeit it's behavior is mapped to the default value of the parameters of the bound action, instead of what is inside the keybindings file. This (bug?) was present even before. See the attached clip below. 1. https://github.com/user-attachments/assets/a9cd2a2c-437b-41a3-bd8e-c4c3a1f350cd 2. https://github.com/user-attachments/assets/4bbfb77c-9019-410e-9d0a-952d4438d2a7 3. https://github.com/user-attachments/assets/ca300e2d-2106-4bb7-865b-5d2ab89cd0f2 https://github.com/user-attachments/assets/ec1e47b6-ff99-461e-93af-af925be4d914 --- Release Notes: - Added `comment_empty_lines` parameter to `editor::ToggleComments` for multiline selections. Use `["editor::ToggleComments", {"comment_empty_lines": true}]` to comment blank lines too (default for Zed keymap now), or `["editor::ToggleComments", {"comment_empty_lines": false}]` to skip them (default for VSCode keymap). --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
210 lines
9.9 KiB
JSON
Executable File
210 lines
9.9 KiB
JSON
Executable File
// documentation: https://zed.dev/docs/key-bindings
|
|
//
|
|
// To see the default key bindings run `zed: open default keymap`
|
|
// from the command palette.
|
|
[
|
|
{
|
|
"bindings": {
|
|
"ctrl-g": "menu::Cancel",
|
|
},
|
|
},
|
|
{
|
|
// Workaround to avoid falling back to default bindings.
|
|
// Unbind so Zed ignores these keys and lets emacs handle them.
|
|
// NOTE: must be declared before the `Editor` override.
|
|
// NOTE: in macos the 'ctrl-x' 'ctrl-p' and 'ctrl-n' rebindings are not needed, since they default to 'cmd'.
|
|
"context": "Editor",
|
|
"bindings": {
|
|
"ctrl-g": null, // currently activates `go_to_line::Toggle` when there is nothing to cancel
|
|
"ctrl-x": null, // currently activates `editor::Cut` if no following key is pressed for 1 second
|
|
// `null` only stops binding resolution in a user keymap, so these use a targeted unbind:
|
|
// `editor::MoveUp`/`MoveDown` propagate when the cursor doesn't move, which at the ends of
|
|
// the buffer would otherwise fall through to these.
|
|
"ctrl-p": ["zed::Unbind", "file_finder::Toggle"],
|
|
"ctrl-n": ["zed::Unbind", "workspace::NewFile"],
|
|
},
|
|
},
|
|
{
|
|
"context": "Editor",
|
|
"bindings": {
|
|
"ctrl-g": "editor::Cancel",
|
|
"alt-g g": "go_to_line::Toggle", // goto-line
|
|
"alt-g alt-g": "go_to_line::Toggle", // goto-line
|
|
"ctrl-space": "editor::SetMark", // set-mark
|
|
"ctrl-@": "editor::SetMark", // set-mark
|
|
"ctrl-x ctrl-x": "editor::SwapSelectionEnds", // exchange-point-and-mark
|
|
"ctrl-f": "editor::MoveRight", // forward-char
|
|
"ctrl-b": "editor::MoveLeft", // backward-char
|
|
"ctrl-n": "editor::MoveDown", // next-line
|
|
"ctrl-p": "editor::MoveUp", // previous-line
|
|
"home": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false }], // move-beginning-of-line
|
|
"end": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
|
|
"ctrl-a": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false }], // move-beginning-of-line
|
|
"ctrl-e": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
|
|
"shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false }], // move-beginning-of-line
|
|
"shift-end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
|
|
"alt-m": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false, "stop_at_indent": true }], // back-to-indentation
|
|
"alt-left": "editor::MoveToPreviousWordStart", // left-word
|
|
"alt-right": "editor::MoveToNextWordEnd", // right-word
|
|
"alt-f": "editor::MoveToNextWordEnd", // forward-word
|
|
"alt-b": "editor::MoveToPreviousWordStart", // backward-word
|
|
"alt-u": "editor::ConvertToUpperCase", // upcase-word
|
|
"alt-l": "editor::ConvertToLowerCase", // downcase-word
|
|
"alt-c": "editor::ConvertToUpperCamelCase", // capitalize-word
|
|
"ctrl-t": "editor::Transpose", // transpose-chars
|
|
"alt-;": ["editor::ToggleComments", { "advance_downwards": false, "comment_empty_lines": false }],
|
|
"ctrl-x ctrl-;": ["editor::ToggleComments", { "advance_downwards": false, "comment_empty_lines": false }],
|
|
"alt-.": "editor::GoToDefinition", // xref-find-definitions
|
|
"alt-?": "editor::FindAllReferences", // xref-find-references
|
|
"alt-,": "pane::GoBack", // xref-pop-marker-stack
|
|
"ctrl-x h": "editor::SelectAll", // mark-whole-buffer
|
|
"ctrl-d": "editor::Delete", // delete-char
|
|
"alt-d": ["editor::DeleteToNextWordEnd", { "ignore_newlines": false, "ignore_brackets": false }], // kill-word
|
|
"alt-backspace": "editor::DeleteToPreviousWordStart", // backward-kill-word
|
|
"alt-delete": "editor::DeleteToPreviousWordStart", // backward-kill-word
|
|
"ctrl-k": "editor::KillRingCut", // kill-line
|
|
"ctrl-w": "editor::Cut", // kill-region
|
|
"alt-w": "editor::Copy", // kill-ring-save
|
|
"ctrl-y": "editor::KillRingYank", // yank
|
|
"ctrl-_": "editor::Undo", // undo
|
|
"ctrl-/": "editor::Undo", // undo
|
|
"ctrl-x u": "editor::Undo", // undo
|
|
"alt-{": "editor::MoveToStartOfParagraph", // backward-paragraph
|
|
"alt-}": "editor::MoveToEndOfParagraph", // forward-paragraph
|
|
"ctrl-up": "editor::MoveToStartOfParagraph", // backward-paragraph
|
|
"ctrl-down": "editor::MoveToEndOfParagraph", // forward-paragraph
|
|
"ctrl-v": "editor::MovePageDown", // scroll-up
|
|
"alt-v": "editor::MovePageUp", // scroll-down
|
|
"ctrl-x [": "editor::MoveToBeginning", // beginning-of-buffer
|
|
"ctrl-x ]": "editor::MoveToEnd", // end-of-buffer
|
|
"alt-<": "editor::MoveToBeginning", // beginning-of-buffer
|
|
"alt->": "editor::MoveToEnd", // end-of-buffer
|
|
"ctrl-home": "editor::MoveToBeginning", // beginning-of-buffer
|
|
"ctrl-end": "editor::MoveToEnd", // end-of-buffer
|
|
"ctrl-l": "editor::ScrollCursorCenterTopBottom", // recenter-top-bottom
|
|
"ctrl-s": "buffer_search::Deploy", // isearch-forward
|
|
"ctrl-r": "buffer_search::Deploy", // isearch-backward
|
|
"alt-^": "editor::JoinLines", // join-line
|
|
"alt-q": "editor::Rewrap", // fill-paragraph
|
|
},
|
|
},
|
|
{
|
|
"context": "Editor && selection_mode", // region selection
|
|
"bindings": {
|
|
"right": "editor::SelectRight",
|
|
"left": "editor::SelectLeft",
|
|
"down": "editor::SelectDown",
|
|
"up": "editor::SelectUp",
|
|
"alt-left": "editor::SelectToPreviousWordStart",
|
|
"alt-right": "editor::SelectToNextWordEnd",
|
|
"pagedown": "editor::SelectPageDown",
|
|
"ctrl-v": "editor::SelectPageDown",
|
|
"pageup": "editor::SelectPageUp",
|
|
"alt-v": "editor::SelectPageUp",
|
|
"ctrl-f": "editor::SelectRight",
|
|
"ctrl-b": "editor::SelectLeft",
|
|
"ctrl-n": "editor::SelectDown",
|
|
"ctrl-p": "editor::SelectUp",
|
|
"home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false }],
|
|
"end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": false }],
|
|
"ctrl-a": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false }],
|
|
"ctrl-e": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": false }],
|
|
"alt-m": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false, "stop_at_indent": true }],
|
|
"alt-f": "editor::SelectToNextWordEnd",
|
|
"alt-b": "editor::SelectToPreviousWordStart",
|
|
"alt-{": "editor::SelectToStartOfParagraph",
|
|
"alt-}": "editor::SelectToEndOfParagraph",
|
|
"ctrl-up": "editor::SelectToStartOfParagraph",
|
|
"ctrl-down": "editor::SelectToEndOfParagraph",
|
|
"ctrl-x [": "editor::SelectToBeginning",
|
|
"ctrl-x ]": "editor::SelectToEnd",
|
|
"alt-<": "editor::SelectToBeginning",
|
|
"alt->": "editor::SelectToEnd",
|
|
"ctrl-home": "editor::SelectToBeginning",
|
|
"ctrl-end": "editor::SelectToEnd",
|
|
"ctrl-g": "editor::Cancel",
|
|
},
|
|
},
|
|
{
|
|
"context": "Editor && (showing_code_actions || showing_completions)",
|
|
"bindings": {
|
|
"ctrl-p": "editor::ContextMenuPrevious",
|
|
"ctrl-n": "editor::ContextMenuNext",
|
|
},
|
|
},
|
|
{
|
|
"context": "Editor && showing_signature_help && !showing_completions",
|
|
"bindings": {
|
|
"ctrl-p": "editor::SignatureHelpPrevious",
|
|
"ctrl-n": "editor::SignatureHelpNext",
|
|
},
|
|
},
|
|
// Example setting for using emacs-style tab
|
|
// (i.e. indent the current line / selection or perform symbol completion depending on context)
|
|
// {
|
|
// "context": "Editor && !showing_code_actions && !showing_completions",
|
|
// "bindings": {
|
|
// "tab": "editor::AutoIndent" // indent-for-tab-command
|
|
// }
|
|
// },
|
|
{
|
|
"context": "Workspace",
|
|
"bindings": {
|
|
"alt-x": "command_palette::Toggle", // execute-extended-command
|
|
"ctrl-x b": "tab_switcher::Toggle", // switch-to-buffer
|
|
"ctrl-x ctrl-b": "tab_switcher::Toggle", // list-buffers
|
|
// "ctrl-x ctrl-c": "workspace::CloseWindow" // in case you only want to exit the current Zed instance
|
|
"ctrl-x ctrl-c": "zed::Quit", // save-buffers-kill-terminal
|
|
"ctrl-x 5 0": "workspace::CloseWindow", // delete-frame
|
|
"ctrl-x 5 2": "workspace::NewWindow", // make-frame-command
|
|
"ctrl-x o": "workspace::ActivateNextPane", // other-window
|
|
"ctrl-x k": "pane::CloseActiveItem", // kill-buffer
|
|
"ctrl-x 0": "pane::CloseActiveItem", // delete-window
|
|
// "ctrl-x 1": "pane::JoinAll", // in case you prefer to delete the splits but keep the buffers open
|
|
"ctrl-x 1": "pane::CloseOtherItems", // delete-other-windows
|
|
"ctrl-x 2": "pane::SplitDown", // split-window-below
|
|
"ctrl-x 3": "pane::SplitRight", // split-window-right
|
|
"ctrl-x ctrl-f": "file_finder::Toggle", // find-file
|
|
"ctrl-x ctrl-s": "workspace::Save", // save-buffer
|
|
"ctrl-x ctrl-w": "workspace::SaveAs", // write-file
|
|
"ctrl-x s": "workspace::SaveAll", // save-some-buffers
|
|
},
|
|
},
|
|
{
|
|
// Workaround to enable using native emacs from the Zed terminal.
|
|
// Unbind so Zed ignores these keys and lets emacs handle them.
|
|
// NOTE:
|
|
// "terminal::SendKeystroke" only works for a single key stroke (e.g. ctrl-x),
|
|
// so override with null for compound sequences (e.g. ctrl-x ctrl-c).
|
|
"context": "Terminal",
|
|
"bindings": {
|
|
// If you want to perfect your emacs-in-zed setup, also consider the following.
|
|
// You may need to enable "option_as_meta" from the Zed settings for "alt-x" to work.
|
|
// "alt-x": ["terminal::SendKeystroke", "alt-x"],
|
|
// "ctrl-x": ["terminal::SendKeystroke", "ctrl-x"],
|
|
// "ctrl-n": ["terminal::SendKeystroke", "ctrl-n"],
|
|
// ...
|
|
"ctrl-x ctrl-c": null, // save-buffers-kill-terminal
|
|
"ctrl-x ctrl-f": null, // find-file
|
|
"ctrl-x ctrl-s": null, // save-buffer
|
|
"ctrl-x ctrl-w": null, // write-file
|
|
"ctrl-x s": null, // save-some-buffers
|
|
},
|
|
},
|
|
{
|
|
"context": "BufferSearchBar > Editor",
|
|
"bindings": {
|
|
"ctrl-s": "search::SelectNextMatch",
|
|
"ctrl-r": "search::SelectPreviousMatch",
|
|
"ctrl-g": "buffer_search::Dismiss",
|
|
},
|
|
},
|
|
{
|
|
"context": "Pane",
|
|
"bindings": {
|
|
"ctrl-alt-left": "pane::GoBack",
|
|
"ctrl-alt-right": "pane::GoForward",
|
|
},
|
|
},
|
|
]
|