Adding conditions to “when” from VS-code extension?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 01:06:59

问题


The code editor I've been using for the past 20 years (codewright) allows you to set a "select mode". When that is set, all keyboard cursor movements extend the selection. In VS Code, you can extend the selection by holding down the shift key (for example, Shift down-arrow), but I am looking for a way to do that without the shift key.

I have written an extension that mostly does it, but I would have had to do far less work if I could have created a new condition for the "when" clause in keybindings.json. For example, I would have liked to change

{ "key": "shift+down",    "command": "cursorDownSelect",
                          "when": "editorTextFocus" },

to something like

{ "key": "down",    "command": "cursorDownSelect",
                    "when": "editorTextFocus || extensionSelectionMode" },
{ "key": "down",    "command": "cursorDown",
                    "when": "editorTextFocus" },

Is there a way to do add a such a condition from an extension?


回答1:


Try using the setContext command in your extension:

vscode.commands.executeCommand('setContext', 'extensionSelectionMode', true)

See VSCode vim for an example of this in action

We are tracking a better API for setting contexts here: https://github.com/Microsoft/vscode/issues/10471



来源:https://stackoverflow.com/questions/44852670/adding-conditions-to-when-from-vs-code-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!