zed icon indicating copy to clipboard operation
zed copied to clipboard

Inline Assistant Doesn't Focus Correctly With Vim Mode

Open jsfour opened this issue 9 months ago • 1 comments

Check for existing issues

  • [X] Completed

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:

  • Go to Vim normal mode
  • Select a block of text
  • Open the inline assistant using the command pallet
  • The inline assistant may not be focused at all (this is one possible state)
  • If the inline assistant is focused, try to type what you want the assistant to do will result in navigating through the code as opposed to typing.

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

jsfour avatar May 08 '24 14:05 jsfour

@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?

ConradIrwin avatar May 10 '24 03:05 ConradIrwin

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"
    }
  }
]

jsfour avatar May 22 '24 00:05 jsfour

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

Testing this more it seems like:

  • Sometimes cmd-shift-p inline assist enter lands you in the editor in a broken state (though it's not completely reliable; confusingly enough it did initially seem broken with your keymap and not mine, but with more testing I realized it was random :D).

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).

ConradIrwin avatar May 23 '24 14:05 ConradIrwin

This is now in today's preview release.

JosephTLyons avatar Jul 17 '24 20:07 JosephTLyons