如何在vscode中为quickPick菜单设置向上/向下键控滚动键?

时间:2016-08-27 06:19:01

标签: visual-studio-code vscode-extensions

简介

我正在 Visual Studio Code 中创建一个扩展程序,用于创建一个' quickPick'菜单,用户可以从中选择选项:

enter image description here

我可以使用向上和向下箭头滚动列表,但我希望能够将其绑定到更像主页的行,例如 ctrl-n ctrl- p 的。我已经 ctrl -n ctrl -p 已经绑定在主命令菜单(ctrl-shift-p)上向上/向下滚动,我希望快速选择也属于这条规则。不幸的是,我的许多ctrl-n上下文绑定都没有生效。

我希望能添加到' keybindings.json'看起来像是:

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

但浏览"默认键盘快捷键"时,我看不到这样的内容。

问题

  1. 如何为快速选择列表创建键绑定?
  2. 我可以创建一个自定义"当"我的扩展的背景?然后我可以指定类似的内容:

    "当" :" myExtensionIsActive&&嗒嗒"

  3. 附加文件

    以下是 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(); 
        });
    

1 个答案:

答案 0 :(得分:6)

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

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