Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored Dec 27, 2022
1 parent 953f7f4 commit c637ec1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
import { getAllUnboundCommands } from 'vs/workbench/services/keybinding/browser/unboundCommands';
import { IKeybindingItemEntry, KeybindingMatches, KeybindingMatch, IKeybindingItem } from 'vs/workbench/services/preferences/common/preferences';
import { ICommandAction, ILocalizedString } from 'vs/platform/action/common/action';
import { isEmptyObject } from 'vs/base/common/types';

export const KEYBINDING_ENTRY_TEMPLATE_ID = 'keybinding.entry.template';

Expand Down Expand Up @@ -348,8 +349,13 @@ class KeybindingItemMatches {
if (matchedWords.length !== words.length) {
return null;
}
if (completeMatch && (!this.isCompleteMatch(firstPart, firstPartMatch) || !this.isCompleteMatch(chordPart, chordPartMatch))) {
return null;
if (completeMatch) {
if (!this.isCompleteMatch(firstPart, firstPartMatch)) {
return null;
}
if (!isEmptyObject(chordPartMatch) && !this.isCompleteMatch(chordPart, chordPartMatch)) {
return null;
}
}
return this.hasAnyMatch(firstPartMatch) || this.hasAnyMatch(chordPartMatch) ? { firstPart: firstPartMatch, chordPart: chordPartMatch } : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,18 @@ suite('KeybindingsEditorModel', () => {
assert.deepStrictEqual(actual[0].keybindingMatches!.firstPart, { keyCode: true });
});

test('filter exact matches also return chords', async () => {
const command = 'a' + uuid.generateUuid();
const expected = aResolvedKeybindingItem({ command, firstChord: { keyCode: KeyCode.KeyK, modifiers: { ctrlKey: true } }, secondChord: { keyCode: KeyCode.KeyC, modifiers: { ctrlKey: true } }, when: 'whenContext1 && whenContext2', isDefault: false });
prepareKeybindingService(expected, aResolvedKeybindingItem({ command, firstChord: { keyCode: KeyCode.Escape, modifiers: { shiftKey: true, metaKey: true } }, secondChord: { keyCode: KeyCode.KeyC, modifiers: { ctrlKey: true } }, when: 'whenContext1 && whenContext2', isDefault: false }));

await testObject.resolve(new Map<string, string>());
const actual = testObject.fetch('"control+k"').filter(element => element.keybindingItem.command === command);
assert.strictEqual(1, actual.length);
assert.deepStrictEqual(actual[0].keybindingMatches!.firstPart, { ctrlKey: true, keyCode: true });
assert.deepStrictEqual(actual[0].keybindingMatches!.chordPart, {});
});

test('filter modifiers are not matched when not completely matched (prefix)', async () => {
testObject = instantiationService.createInstance(KeybindingsEditorModel, OperatingSystem.Macintosh);
const term = `alt.${uuid.generateUuid()}`;
Expand Down

0 comments on commit c637ec1

Please sign in to comment.