microsoft/vscode

Missing keybinding for navigation in Quick Fix contextual menu

gibbok opened this issue ยท 30 comments

The problem:

It is not possible to define custom shortcuts for Quick Fix contextual menu.

  • Use latest stable build of VS code and open a TypeScript project.
  • Open the Quick Fix by intentionally making a mistake in the code.
  • Press CTRL + . to open the Quick Fix contextual menu suggestions.
  • It is possible to select an item from the menu by using UP/DOWN arrow key.
  • ISSUE: it is no possible to define custom shortcuts in order to select the prev/next Quick Fix suggestion in the contextual menu.
    Would be great to have customize selection of the prev/next suggestion, similarly to IntelliSense (example below):
    {
      "key": "ctrl+k",
      "command": "selectPrevSuggestion",
      "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
    },
    {
      "key": "ctrl+j",
      "command": "selectNextSuggestion",
      "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
    },

To my knowledge that isn't possible because we are using a native menu.

so sad, i am trying to bind the up/down to 'j', 'k', and blocked here. is there any workaround?

So sad, can't use shortcut to move in Quick Fix contextual menu break my coding experience. can you fix this bug quickly?

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

please fix this quickly

๐Ÿ™‚ This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

Please prioritize. The lack of custom binding is a productivity killer for vim-like users. The workflow is interrupted each time you have to reach for the arrow keys. And some linux-centric keyboards don't even have the arrow keys. They would have to press combo keys to get the arrow keypress event.

is there any internal API do get the code actions? having them displayed in menu at the top like Quick Open would already solve this issue

I created a extension as a workaround:
https://marketplace.visualstudio.com/items?itemName=pascalsenn.keyboard-quickfix

It uses the quick open picker to display codeactions.
It is possible to navigate through these with the keyboard

@PascalSenn did you figure out a good way to display "No code actions available"? That's the road block I ran into (though not really a big deal, just curious).

@SeeminglyScience i did not think about that. Added it in 0.0.4.
Might take a few minutes to show up on the market place
image

@PascalSenn could you please add a command like keyboard-quickfix.toggleQuickFix to open/close quickFix using the same command?

Have a lot to do currently, but you can open an issue here:
https://github.com/PascalSenn/keyboard-quickfix/issues

Currently as a work around I use the following key biding in keybindings.json, I hope you find it useful.

[
  {
    "key": "ctrl+k",
    "command": "selectPrevSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+j",
    "command": "selectNextSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  }
]

@gibbok

It doesn't work for me. I added these mappings and navigation inside the popup window with suggestions isn't working. I don't have any other commands bound to these combinations.

I am also trying to use vim keyboard shortcuts for the quickfix menu. Seems there is no solution yet...

My workaround is using the Hotkeys app

#IfWinActive, Visual Studio Code
^j::
Send, {Down}
return

#IfWinActive, Visual Studio Code
^k::
Send, {Up}
return

#IfWinActive, Visual Studio Code
^[::
Send, {Esc}
return

Currently as a work around I use the following key biding in keybindings.json, I hope you find it useful.

[
  {
    "key": "ctrl+k",
    "command": "selectPrevSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+j",
    "command": "selectNextSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  }
]

This works for the autocomplete menu very well (I use alt-j/k, but works great), however it doesn't work with the quick fix menu. For that you need the keyboard quickfix extension

My workaround is using the Hotkeys app

#IfWinActive, Visual Studio Code
^j::
Send, {Down}
return

#IfWinActive, Visual Studio Code
^k::
Send, {Up}
return

#IfWinActive, Visual Studio Code
^[::
Send, {Esc}
return

Is that for Linux? If so could you explain how do I apply that in my Linux(PopOS)! Linux noob user here. I really want that shortcuts workaround. Thanks in advance.

BTW a shallow workaround: Press "alt+enter" when the quick fix pops up on the screen, but you can't switch among options, but if there is only one option its will be enough.

Well, I just figured out a solution for this issue, download AutoKey app for Linux and set this shortcut keyboard as you like. An example below with my preferences!
image

Still no default keybindings for navigating through the quick-fix list?

I also want a default keybinding for this. Since I switch back and forth between Mac & Windows a lot I often use ctrl + n and ctrl+ p to navigate the menu a lot. I've basically mapped most of the keybindings to match my experience on mac but this one really caught me out as I can't navigate the menu with the same shortcuts.

Does anyone have any workaround for this issue?
I really like the idea of customizing keybinding for navigating in the context menu.

First, read the whole discussion before asking which is already been answered, second, use this extension, like it was said before: https://github.com/PascalSenn/keyboard-quickfix
This replaces the quickfix context menu with the quick open window, which keybindings can be customized

Thanks, @ohechtl. I read the discussion, but I missed the solution from @PascalSenn.
Thanks, @PascalSenn for the extension. Really helpful.

(see below comment for updated keybindings id/criteria)

With the new Code Action Widget (which applies to the refactoring and source controls from the context menu, the lightbulb widget, and quickfixes), custom keybindings for navigation, selection, and previews have been added.

Currently the widget is under an experimental setting "editor.experimental.useCustomCodeActionMenu": true. Can also be found by going to Editor โ€บ Experimental: Use Custom Code Action Menu!

Take a look at this snippet for keybindings.json

[
  {
    "key": "ctrl+k",
    "when": "CodeActionMenuVisible",
    "command": "focusPreviousCodeAction"
  },
  {
    "key": "ctrl+j",
    "when": "CodeActionMenuVisible",
    "command": "focusNextCodeAction"
  }
]

With the new Code Action Widget (which applies to the refactoring and source controls from the context menu, the lightbulb widget, and quickfixes), custom keybindings for navigation, selection, and previews have been added.

Currently the widget is under an experimental setting "editor.experimental.useCustomCodeActionMenu": true. Can also be found by going to Editor โ€บ Experimental: Use Custom Code Action Menu!

Take a look at this snippet for keybindings.json

[
  {
    "key": "ctrl+k",
    "when": "CodeActionMenuVisible",
    "command": "focusPreviousCodeAction"
  },
  {
    "key": "ctrl+j",
    "when": "CodeActionMenuVisible",
    "command": "focusNextCodeAction"
  }
]

The commands changed into selectNextCodeAction and selectPrevCodeAction in the new update.

in the new action menu is no longer working hotkey selection on the first letter of the phrase, now only works with the arrows ...
Is it just me who has this problem?

Couple modifications in the latest update! As @MejanH mentioned, the commands are changed into selectNextCodeAction and selectPrevCodeAction in the new update.

A problem that @d-khomenko brought up is resolved with changing CodeActionMenuVisible to camel-case - codeActionMenuVisible

[
  {
    "key": "ctrl+k",
    "when": "codeActionMenuVisible",
    "command": "selectPrevCodeAction"
  },
  {
    "key": "ctrl+j",
    "when": "codeActionMenuVisible",
    "command": "selectNextCodeAction"
  }
]