简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM