我正在 Visual Studio Code 中创建一个扩展程序,用于创建一个' quickPick'菜单,用户可以从中选择选项:
我可以使用向上和向下箭头滚动列表,但我希望能够将其绑定到更像主页的行,例如 ctrl-n 和 ctrl- p 的。我已经 ctrl -n 和 ctrl -p 已经绑定在主命令菜单(ctrl-shift-p)上向上/向下滚动,我希望快速选择也属于这条规则。不幸的是,我的许多ctrl-n上下文绑定都没有生效。
我希望能添加到' keybindings.json'看起来像是:
{
"key": "ctrl+n",
"command": "cursorDown",
"when": "quickPickFocus"
},
但浏览"默认键盘快捷键"时,我看不到这样的内容。
我可以创建一个自定义"当"我的扩展的背景?然后我可以指定类似的内容:
"当" :" 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();
});
答案 0 :(得分:6)
您只需添加错误的键绑定command
和when
,请尝试将其添加到您的keybindings.json
{
"key": "ctrl+n",
"command": "workbench.action.quickOpenSelectNext",
"when": "!editorFocus"
},
{
"key": "ctrl+p",
"command": "workbench.action.quickOpenSelectPrevious",
"when": "!editorFocus"
}