Preserve keybinding default metadata when key is not set#317032
Open
n-gist wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts extension-contributed keybinding handling so entries with an empty key can preserve associated default metadata such as when clauses.
Changes:
- Allows empty-string contributed keybindings to become
nullkeybinding rules instead of being dropped. - Keeps extension keybinding registry entries even when the parsed keybinding is
null. - Adds a resolver test for preserving an unbound keybinding override.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/vs/workbench/services/keybinding/browser/keybindingService.ts |
Changes the guard so only missing keybinding fields are rejected. |
src/vs/platform/keybinding/common/keybindingsRegistry.ts |
Stores extension keybinding rules even when rule.keybinding is null. |
src/vs/platform/keybinding/test/common/keybindingResolver.test.ts |
Adds coverage for preserving an empty keybinding override through removal handling. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR enables (or fixes) the ability for extensions to define default keybinding metadata without setting an explicit key.
Currently, the metadata (most importantly the
whenproperty) is lost when defining a keybinding like this, even though the schema itself is valid (command2):{ "key": "shift+g", "command": "extension.command1", "when": "extensionContext1" }, { "key": "", "command": "extension.command2", "when": "extensionContext2" }Result:
As a result, extensions cannot provide optional bindable commands without instructing extension users about the correct
whenvalues, which can be complex, may evolve across extension versions and generally should not be a concern for extension users when possible.This change preserves default values, so extension users only need to set the keybinding:
Changes
What initially looked like it would require a special case turned out, after investigation, to be a straightforward fix:
vscode/src/vs/workbench/services/keybinding/browser/keybindingService.ts
Lines 626 to 629 in aa21abc
This truthiness check was filtering out empty
keycases. It can safely be replaced with a check forundefinedonly, since after that KeybindingParser.parseKeybinding(keybinding) resolves empty strings tonull, which is a valid value forIExtensionKeybindingRule.Later, another filter:
vscode/src/vs/platform/keybinding/common/keybindingsRegistry.ts
Lines 154 to 156 in aa21abc
This appears to be another historical truthiness shortcut rather than an intentional semantic filter, since:
nullvalues correctlynullvalues correctlynullIn this context,
nullshould not mean “discard rule”, but rather “keep rule, but with no keybinding”.Adjusting the first guard and removing the second filter prevents keybindings from being discarded, which in turn preserves the keybinding metadata.