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
39.25k stars 2.03k forks source link

vim: Command Palette -> Inline Assistant doesn't remove vim bindings #11559

Open jsfour opened 1 month ago

jsfour commented 1 month ago

Check for existing issues

Describe the bug / provide steps to reproduce it

When trying to use the inline assistant with VIM mode enabled the auto focus is broken.

Steps to reproduce:

I think this may be because when the inline assistant is opened vim is stuck in normal mode despite the cursor changing. If I open the inline assistant and then switch to insert mode everything works fine. The desired ux would be to automatically switch to insert mode when the inline assistant is focused -- Zed did this before but it stopped working a couple of weeks ago.

Environment

Zed: v0.133.7 (Zed) OS: macOS 14.2.1 Memory: 32 GiB Architecture: aarch64

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

CleanShot 2024-05-08 at 07 08 50

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

No response

ConradIrwin commented 1 month ago

@jsfour Thanks for reporting this!

I am unable to reproduce this on my end, but I can see that it is happening to you very reliably...

Do you have any custom keybindings? Does this still reproduce if you use ctrl-enter to get the inline assistant instead of going via the command palette?

jsfour commented 1 month ago

Yep. Here is my keymaps.json

[
  {
    "bindings": {
      "ctrl-p": "file_finder::Toggle",
      "ctrl-f": "pane::DeploySearch",
      "ctrl-n": [
        "workspace::ToggleLeftDock",
        {
          "focus": true
        }
      ],
      "ctrl-b z": "workspace::ToggleZoom",
      "ctrl-b down": ["workspace::ActivatePaneInDirection", "Down"],
      "ctrl-b up": ["workspace::ActivatePaneInDirection", "Up"],
      "ctrl-b left": ["workspace::ActivatePaneInDirection", "left"],
      "ctrl-b right": ["workspace::ActivatePaneInDirection", "right"]
    }
  },
  {
    "context": "Dock",
    "bindings": {
      "ctrl-w h": ["workspace::ActivatePaneInDirection", "Left"],
      "ctrl-w l": ["workspace::ActivatePaneInDirection", "Right"],
      "ctrl-w k": ["workspace::ActivatePaneInDirection", "Up"],
      "ctrl-w j": ["workspace::ActivatePaneInDirection", "Down"]
    }
  },
  {
    "context": "Editor && (vim_mode == normal || vim_mode == visual) && !VimWaiting && !menu",
    "bindings": {
      "\\ c space": [
        "editor::ToggleComments",
        {
          "advance_downwards": false
        }
      ]
    }
  },
  {
    "context": "ProjectPanel && not_editing",
    "bindings": {
      "k": "menu::SelectPrev",
      "j": "menu::SelectNext",
      "m": "project_panel::Rename",
      "enter": "project_panel::Open"
    }
  }
]
ConradIrwin commented 1 month ago

Thanks! That looks fine (though you probably need to upper-case left and right for ctrl-b).

Testing this more it seems like:

For now you should be able to work around this by using ctrl-enter to open the inline assistant. I think there's a bug in our focus handling logic that doesn't correctly account for the jump from editor -> command -> inline assist. (But I'm not yet sure what makes it work sometimes and not others).