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
45.01k stars 2.43k forks source link

Custom Keybind Causes 3-Second Delay in Inline Assist Prompt #13543

Closed jenslys closed 1 month ago

jenslys commented 1 month ago

Check for existing issues

Describe the bug / provide steps to reproduce it

If you add a custom bind/keymap to the inline assist, there is a noticeable 3 second delay before the prompt shows up.

  1. Add a custom keybind for the inline assistant:
    {
    "context": "Editor && mode == full",
    "bindings": {
        "cmd-k": "assistant::InlineAssist"
    }
    }
  2. Mark som code and press the custom bind.

Environment

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

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

Default keymap vs Custom

Screenshot 2024-06-26 at 14 18 50

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

Zed.log


ojkelly commented 1 month ago

I was about to make this exact issue, but for a bind to open the command_palette.

      "cmd-k": "command_palette::Toggle",

I think the issue stems from the many many default bindings that are chords and zed's waiting to see if there is a follow up command.

A quick sample from the default keymap.

      "cmd-k cmd-s": "zed::OpenKeymap",
      "cmd-k cmd-t": "theme_selector::Toggle",
      "cmd-k m": "language_selector::Toggle",
      "cmd-k cmd-left": ["workspace::ActivatePaneInDirection", "Left"],
      "cmd-k cmd-right": ["workspace::ActivatePaneInDirection", "Right"],
      "cmd-k cmd-up": ["workspace::ActivatePaneInDirection", "Up"],
      "cmd-k cmd-down": ["workspace::ActivatePaneInDirection", "Down"],
      "cmd-k shift-left": ["workspace::SwapPaneInDirection", "Left"],
      "cmd-k shift-right": ["workspace::SwapPaneInDirection", "Right"],
      "cmd-k shift-up": ["workspace::SwapPaneInDirection", "Up"],
      "cmd-k shift-down": ["workspace::SwapPaneInDirection", "Down"],

I understand the need to wait, and can see this may not be easy to solve.

For myself, I'd be happy to remove all the other keybindings and have mine overwrite.

Maybe something like CSS's !important could work?

      "!important cmd-k": "command_palette::Toggle",
ConradIrwin commented 1 month ago

We could potentially make it so that if prefix is defined in the user config, but the multi-key bindings are in the default config, we make it take precedence automatically.

The main downside to that is that you can accidentally override a bunch of builtin keystrokes, but it seems better than the status quo.

ojkelly commented 1 month ago

The main downside to that is that you can accidentally override a bunch of builtin keystrokes, but it seems better than the status quo.

From my perspective I'm not likely to memorise all the multi-key combos, and would instead search for them as needed. So I'm totally fine with losing them all. I can imagine it may be unexpected to some though. Maybe a code hint or something in the user config to let us know it's disabling a bunch of shortcuts?

JosephTLyons commented 1 month ago

This should be included in Zed v0.146.0-pre.