How can I set up / down scroll keys for quick menu in vscode?

Introduction

I am creating an extension in Visual Studio Code that creates a "quickPick" menu from which the user can select options:

enter image description here

I can use the up and down arrows to scroll through the list, but I want to be able to bind this to something more friendly to the home bar, for example ctrl-n and ctrl-p. I have ctrl-n and ctrl-p that are already tied to scroll up / down in the main command menu (ctrl-shift-p), and I was hoping that quick choices would fall under this rule. Unfortunatley, none of my many ctrl-n context bindings take effect.

I hope that I can add to "keybindings.json", which looks something like this:

 {
        "key": "ctrl+n", 
        "command": "cursorDown", 
        "when": "quickPickFocus"
    }, 

" ".

  • ?
  • "" ? - :

    "": "myExtensionIsActive && blah"

ctrl-n keybindings.json:

    {
        "key": "ctrl+n", 
        "command": "cursorDown", 
        "when": "editorTextFocus"
    }, 
    {
        "key": "ctrl+n", 
        "command": "workbench.action.quickOpenNavigateNext", 
        "when": "inQuickOpen"
    }, 
   {
        "key": "ctrl+n", 
        "command": "showNextParameterHint", 
        "when": "editorTextFocus && parameterHintsVisible"
    }, 
   {
        "key": "ctrl+n", 
        "command": "selectNextQuickFix", 
        "when": "editorFocus && quickFixWidgetVisible"
    }, 
    {
        "key": "ctrl+n", 
        "command": "selectNextSuggestion", 
        "when": "editorTextFocus && suggestWidgetVisible"
    }, 

, quickPick:

 var themeList = this.getThemeList()
  vscode.window.showQuickPick(themeList)
    .then(val => {
      // Update the status bar
      this.cmdChannel.text = `Theme: ${val}`
      this.cmdChannel.show(); 
    });
+4
1

command when, , keybindings.json

        {
            "key": "ctrl+n",
            "command": "workbench.action.quickOpenSelectNext",
            "when": "!editorFocus"
        },
        {
            "key": "ctrl+p",
            "command": "workbench.action.quickOpenSelectPrevious",
            "when": "!editorFocus"
        }
+2

Source: https://habr.com/ru/post/1652677/


All Articles