question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow extensions to contribute a default when clause to be used when a user add a key binding for the command

See original GitHub issue

Related: https://github.com/microsoft/vscode/issues/40389#issuecomment-738419359

Commands today can often have complex when clauses for the conditional for when they should apply, but these conditions aren’t able to be expressed to the user when they add a key binding. Maybe we could add a defaultWhen or keybindingWhen (or something like that) property to commands in the package.json, so that when a user add a key binding for that command, the when clause would be populated with that value.

Alternatively, I was thinking that we could re-use the when clause of the command’s commandPalette contribution to get at a reasonable default, but it might be tricky and we’d need to discount any false clauses.

Another option (though larger in scope of what I am proposing/wanting here) would be to allow having an entry in the keybindings contribution point without the actual key, so that it would be used as the “template” for when a user adds a binding. This could also double as a way for extensions to opt-out commands from key bindings altogether, by setting "when": false like the commandPalette contribution point. As there are plenty of commands that an extension can have that they can’t really support a user adding a keybinding for. But that 2nd point, is I think out of scope of this issue.

/cc @alexdima, @jrieken

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sandy081commented, Dec 4, 2020

@alexdima I felt the feature is asking for more like

  • Defining defaultWhen or keybindingWhen (or something like that) property to commands in the package.json,
  • Or re-use the when clause of the command’s commandPalette contribution to get at a reasonable default, but it might be tricky and we’d need to discount any false clauses.

Since Keybindings editor is just one kind of UI to add keybinding and users can also add keybindings directly from json file, I thought it shall be something that has to be supported by core keybindings.

0reactions
vscode-triage-botcommented, Jan 24, 2021

This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

Read more comments on GitHub >

github_iconTop Results From Across the Web

when clause contexts | Visual Studio Code Extension API
For example, VS Code uses when clauses to enable or disable command keybindings, which you can see in the Default Keybindings JSON (Preferences:...
Read more >
Add suggestions for key binding when clause contexts #9303
When the user is creating custom keybindings, we now have suggestions (IntelliSense) for command ids. Suggestions for then when clause contexts (ex, editorFocus ......
Read more >
VS Code keyboard-fu: custom keyboard shortcuts that will ...
Visual Studio Code (VS Code) comes with default keybindings for many of its built-in commands. You just need to learn some of these...
Read more >
Key Bindings for Visual Studio Code - vscode-docs
Visual Studio Code lets you perform most tasks directly from the keyboard. This page lists out the default bindings and describes how you...
Read more >
VSCode: Effect of not removing a default keybinding in ...
So, the user keybindings always override the default keybindings given the same when clause. Even if the when clauses are different, if two ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found