Treat removing keybindings with when = true as if they wouldn't have a when clause (#162945)

Fixes #160604: Treat removing keybindings with `when = true` as if they wouldn't have a when clause
This commit is contained in:
Alexandru Dima 2022-10-07 15:52:42 +02:00 committed by GitHub
parent 6d59844e1c
commit e97990e4ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -70,7 +70,10 @@ export class KeybindingResolver {
if (keypressChordPart && defaultKb.keypressParts[1] !== keypressChordPart) {
return false;
}
if (when) {
// `true` means always, as does `undefined`
// so we will treat `true` === `undefined`
if (when && when.type !== ContextKeyExprType.True) {
if (!defaultKb.when) {
return false;
}

View file

@ -235,7 +235,7 @@ suite('KeybindingResolver', () => {
]);
});
test('issue #157751: Keyboard Shortcuts: Change When Expression might actually remove keybinding in Insiders', () => {
test('issue #157751: Auto-quoting of context keys prevents removal of keybindings via UI', () => {
const defaults = [
kbItem(KeyCode.KeyA, 'command1', null, ContextKeyExpr.deserialize(`editorTextFocus && activeEditor != workbench.editor.notebook && editorLangId in julia.supportedLanguageIds`), true),
];
@ -246,6 +246,17 @@ suite('KeybindingResolver', () => {
assert.deepStrictEqual(actual, []);
});
test('issue #160604: Remove keybindings with when clause does not work', () => {
const defaults = [
kbItem(KeyCode.KeyA, 'command1', null, undefined, true),
];
const overrides = [
kbItem(KeyCode.KeyA, '-command1', null, ContextKeyExpr.true(), false),
];
const actual = KeybindingResolver.handleRemovals([...defaults, ...overrides]);
assert.deepStrictEqual(actual, []);
});
test('contextIsEntirelyIncluded', () => {
const toContextKeyExpression = (expr: ContextKeyExpression | string | null) => {
if (typeof expr === 'string' || !expr) {