从 VS 代码扩展中向“何时”添加条件?

Bar*_*ley 9 visual-studio-code vscode-extensions

过去 20 年我一直在使用的代码编辑器(codewright)允许您设置“选择模式”。设置后,所有键盘光标移动都会扩展选择。在 VS Code 中,您可以通过按住 shift 键(例如,Shift 向下箭头)来扩展选择范围,但我正在寻找一种无需使用 shift 键的方法。

我已经编写了一个主要用于它的扩展,但是如果我可以为keybindings.json. 例如,我想改变

{ "key": "shift+down",    "command": "cursorDownSelect",
                          "when": "editorTextFocus" },
Run Code Online (Sandbox Code Playgroud)

{ "key": "down",    "command": "cursorDownSelect",
                    "when": "editorTextFocus || extensionSelectionMode" },
{ "key": "down",    "command": "cursorDown",
                    "when": "editorTextFocus" },
Run Code Online (Sandbox Code Playgroud)

有没有办法从扩展中添加这样的条件?

Mat*_*ner 7

尝试setContext在您的扩展中使用命令:

vscode.commands.executeCommand('setContext', 'extensionSelectionMode', true)
Run Code Online (Sandbox Code Playgroud)

有关此操作的示例,请参阅VSCode vim

我们正在跟踪更好的 API 以在此处设置上下文:https : //github.com/Microsoft/vscode/issues/10471