9

介绍

我在Visual Studio Code中创建了一个扩展,它创建了一个“quickPick”菜单,用户可以从中选择选项:

在此处输入图像描述

我可以使用向上和向下箭头滚动列表,但我希望能够将其绑定到对主行更友好的东西,如ctrl-nctrl-p。我已经在主命令菜单 (ctrl-shift-p) 上绑定了ctrl-nctrl-p来向上/向下滚动,我希望快速选择也符合此规则。不幸的是,我的许多 ctrl-n 上下文绑定都没有生效。

我希望我可以添加到“keybindings.json”中,看起来像:

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

但是在浏览“默认键盘快捷键”时我看不到这样的东西。

问题

  1. 您如何为快速选择列表创建键绑定?

  2. 我可以为我的扩展程序创建一个自定义的“何时”上下文吗?然后我可以指定如下内容:

    “何时”:“myExtensionIsActive && 等等”

附加文件

以下是我的keybindings.json中所有被覆盖的 ctrl-n 键绑定:

    {
        "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 回答 1

12

您只是添加了错误的键绑定commandwhen请尝试将其添加到您的keybindings.json

        {
            "key": "ctrl+n",
            "command": "workbench.action.quickOpenSelectNext",
            "when": "!editorFocus"
        },
        {
            "key": "ctrl+p",
            "command": "workbench.action.quickOpenSelectPrevious",
            "when": "!editorFocus"
        }
于 2017-06-29T07:17:50.400 回答