zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.72k stars 3.06k forks source link

When setting all the cmd+\\ keybindings to null the key binding still gets triggered #16187

Closed ExploHash closed 2 months ago

ExploHash commented 3 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Set the keymap.json to

// Zed keymap
//
// For information on binding keys, see the Zed
// documentation: https://zed.dev/docs/key-bindings
//
// To see the default key bindings run `zed: open default keymap`
// from the command palette.
[
  {
    "context": "Workspace",
    "bindings": {
      "cmd-\\": null
    }
  },
  {
    "context": "Editor",
    "bindings": {
      "cmd-\\": null
    }
  },
  {
    "context": "Editor && mode == full",
    "bindings": {
      "cmd-\\": null
    }
  },
  {
    "context": "Pane",
    "bindings": {
      "cmd-\\": null
    }
  },
  {
    "context": "CommandPalette",
    "bindings": {
      "cmd-\\": null
    }
  },
  {
    "context": "Terminal",
    "bindings": {
      "cmd-\\": null
    }
  },
  {
    "context": "BufferSearchBar",
    "bindings": {
      "cmd-\\": null
    }
  }
]

And do CMD+\ and see a pane still splits which is the default keybinding

Environment

Zed: v0.148.0 (Zed Preview) OS: macOS 14.5.0 Memory: 16 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

No logging happens

notpeter commented 3 months ago

I can reproduce.

As cmd-\\ is only mapped in one place in the default MacOS keybinding: https://github.com/zed-industries/zed/blob/910dbe9ce6c8e1441ca0822aacc5394a34143062/assets/keymaps/default-macos.json#L349

This is the only context you should need to remap:

  {
    "context": "Editor",
    "bindings": {
      "cmd-\\": null
    }
  },

But that's not working. Thanks for reporting.

ExploHash commented 3 months ago

@notpeter Thanks for checking :), good to hear that I didn't do anything stupid

CharlesChen0823 commented 2 months ago

because "ctrl-\" also register into macos system menus, link here which you cannot remap this actions.

notpeter commented 2 months ago

Thanks @CharlesChen0823 that it. Because we include the cmd-\ in the menu, MacOS captures it. If you would like to unmap cmd-\ you will need this:

  {
    "context": "Editor",
    "bindings": {
      "cmd-\\": null
    }
  },

And you will need to assign an alternate shortcut under System Preferences -> Keyboard -> Keyboard Shortcuts -> App Shortcuts for Split Right for Zed.

Screenshot 2024-08-15 at 13 17 43

Then your View->Editor Layout menu will change from this to this: Screenshot 2024-08-15 at 13 16 11image

And cmd-\ will truly be a no-op. @ExploHash Please let me know if this works for you.

ExploHash commented 2 months ago

Ahh I see, thanks! It works kind of, the reason why I asked this is because I created a custom shortcut on CMD+\ in settings (to open a terminal). After remapping split right, now nothing happens at all even though in other applications CMD+\ does trigger my custom shortcut.

But it's fine I could just choose another keybinding even though it's interesting that it now doesn't trigger anything haha

notpeter commented 2 months ago

Once you've gotten MacOS out of the way, instead of setting it to null, rebind it to whatever action you want. For example, this works for me:

  {
    "bindings": {
      "cmd-\\": "terminal_panel::ToggleFocus"
    }
  },
ExploHash commented 2 months ago

@notpeter Its a shortcut in macos, so I kinda want Zed not to do anything with cmd + \ at alll