Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 545
Barry Bentley Avatar asked Jun 30 '17 18:06

Barry Bentley


1 Answers

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

like image 91
Matt Bierner Avatar answered Sep 24 '22 02:09

Matt Bierner