提交 7e407b54 编写于 作者: S Sandeep Somavarapu

Fix #98489

上级 112417a0
...@@ -421,22 +421,6 @@ class KeybindingItemMatches { ...@@ -421,22 +421,6 @@ class KeybindingItemMatches {
return this.wordMatchesMetaModifier(word); return this.wordMatchesMetaModifier(word);
} }
private wordMatchesMetaModifier(word: string): boolean {
if (matchesPrefix(this.modifierLabels.ui.metaKey, word)) {
return true;
}
if (matchesPrefix(this.modifierLabels.aria.metaKey, word)) {
return true;
}
if (matchesPrefix(this.modifierLabels.user.metaKey, word)) {
return true;
}
if (matchesPrefix(localize('meta', "meta"), word)) {
return true;
}
return false;
}
private matchesCtrlModifier(keybinding: ResolvedKeybindingPart | null, word: string): boolean { private matchesCtrlModifier(keybinding: ResolvedKeybindingPart | null, word: string): boolean {
if (!keybinding) { if (!keybinding) {
return false; return false;
...@@ -447,19 +431,6 @@ class KeybindingItemMatches { ...@@ -447,19 +431,6 @@ class KeybindingItemMatches {
return this.wordMatchesCtrlModifier(word); return this.wordMatchesCtrlModifier(word);
} }
private wordMatchesCtrlModifier(word: string): boolean {
if (matchesPrefix(this.modifierLabels.ui.ctrlKey, word)) {
return true;
}
if (matchesPrefix(this.modifierLabels.aria.ctrlKey, word)) {
return true;
}
if (matchesPrefix(this.modifierLabels.user.ctrlKey, word)) {
return true;
}
return false;
}
private matchesShiftModifier(keybinding: ResolvedKeybindingPart | null, word: string): boolean { private matchesShiftModifier(keybinding: ResolvedKeybindingPart | null, word: string): boolean {
if (!keybinding) { if (!keybinding) {
return false; return false;
...@@ -470,19 +441,6 @@ class KeybindingItemMatches { ...@@ -470,19 +441,6 @@ class KeybindingItemMatches {
return this.wordMatchesShiftModifier(word); return this.wordMatchesShiftModifier(word);
} }
private wordMatchesShiftModifier(word: string): boolean {
if (matchesPrefix(this.modifierLabels.ui.shiftKey, word)) {
return true;
}
if (matchesPrefix(this.modifierLabels.aria.shiftKey, word)) {
return true;
}
if (matchesPrefix(this.modifierLabels.user.shiftKey, word)) {
return true;
}
return false;
}
private matchesAltModifier(keybinding: ResolvedKeybindingPart | null, word: string): boolean { private matchesAltModifier(keybinding: ResolvedKeybindingPart | null, word: string): boolean {
if (!keybinding) { if (!keybinding) {
return false; return false;
...@@ -493,22 +451,6 @@ class KeybindingItemMatches { ...@@ -493,22 +451,6 @@ class KeybindingItemMatches {
return this.wordMatchesAltModifier(word); return this.wordMatchesAltModifier(word);
} }
private wordMatchesAltModifier(word: string): boolean {
if (matchesPrefix(this.modifierLabels.ui.altKey, word)) {
return true;
}
if (matchesPrefix(this.modifierLabels.aria.altKey, word)) {
return true;
}
if (matchesPrefix(this.modifierLabels.user.altKey, word)) {
return true;
}
if (matchesPrefix(localize('option', "option"), word)) {
return true;
}
return false;
}
private hasAnyMatch(keybindingMatch: KeybindingMatch): boolean { private hasAnyMatch(keybindingMatch: KeybindingMatch): boolean {
return !!keybindingMatch.altKey || return !!keybindingMatch.altKey ||
!!keybindingMatch.ctrlKey || !!keybindingMatch.ctrlKey ||
...@@ -574,4 +516,62 @@ class KeybindingItemMatches { ...@@ -574,4 +516,62 @@ class KeybindingItemMatches {
} }
return false; return false;
} }
private wordMatchesAltModifier(word: string): boolean {
if (strings.equalsIgnoreCase(this.modifierLabels.ui.altKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(this.modifierLabels.aria.altKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(this.modifierLabels.user.altKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(localize('option', "option"), word)) {
return true;
}
return false;
}
private wordMatchesCtrlModifier(word: string): boolean {
if (strings.equalsIgnoreCase(this.modifierLabels.ui.ctrlKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(this.modifierLabels.aria.ctrlKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(this.modifierLabels.user.ctrlKey, word)) {
return true;
}
return false;
}
private wordMatchesMetaModifier(word: string): boolean {
if (strings.equalsIgnoreCase(this.modifierLabels.ui.metaKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(this.modifierLabels.aria.metaKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(this.modifierLabels.user.metaKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(localize('meta', "meta"), word)) {
return true;
}
return false;
}
private wordMatchesShiftModifier(word: string): boolean {
if (strings.equalsIgnoreCase(this.modifierLabels.ui.shiftKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(this.modifierLabels.aria.shiftKey, word)) {
return true;
}
if (strings.equalsIgnoreCase(this.modifierLabels.user.shiftKey, word)) {
return true;
}
return false;
}
} }
...@@ -34,7 +34,7 @@ class AnAction extends Action { ...@@ -34,7 +34,7 @@ class AnAction extends Action {
} }
} }
suite('KeybindingsEditorModel test', () => { suite('KeybindingsEditorModel', () => {
let instantiationService: TestInstantiationService; let instantiationService: TestInstantiationService;
let testObject: KeybindingsEditorModel; let testObject: KeybindingsEditorModel;
...@@ -568,6 +568,46 @@ suite('KeybindingsEditorModel test', () => { ...@@ -568,6 +568,46 @@ suite('KeybindingsEditorModel test', () => {
assert.deepEqual(actual[0].keybindingMatches!.firstPart, { keyCode: true }); assert.deepEqual(actual[0].keybindingMatches!.firstPart, { keyCode: true });
}); });
test('filter modifiers are not matched when not completely matched (prefix)', async () => {
testObject = instantiationService.createInstance(KeybindingsEditorModel, OperatingSystem.Macintosh);
const term = `alt.${uuid.generateUuid()}`;
const command = `command.${term}`;
const expected = aResolvedKeybindingItem({ command, firstPart: { keyCode: KeyCode.Escape }, isDefault: false });
prepareKeybindingService(expected, aResolvedKeybindingItem({ command: 'some_command', firstPart: { keyCode: KeyCode.Escape, modifiers: { altKey: true } }, isDefault: false }));
await testObject.resolve(new Map<string, string>());
const actual = testObject.fetch(term);
assert.equal(1, actual.length);
assert.equal(command, actual[0].keybindingItem.command);
assert.equal(1, actual[0].commandIdMatches?.length);
});
test('filter modifiers are not matched when not completely matched (includes)', async () => {
testObject = instantiationService.createInstance(KeybindingsEditorModel, OperatingSystem.Macintosh);
const term = `abcaltdef.${uuid.generateUuid()}`;
const command = `command.${term}`;
const expected = aResolvedKeybindingItem({ command, firstPart: { keyCode: KeyCode.Escape }, isDefault: false });
prepareKeybindingService(expected, aResolvedKeybindingItem({ command: 'some_command', firstPart: { keyCode: KeyCode.Escape, modifiers: { altKey: true } }, isDefault: false }));
await testObject.resolve(new Map<string, string>());
const actual = testObject.fetch(term);
assert.equal(1, actual.length);
assert.equal(command, actual[0].keybindingItem.command);
assert.equal(1, actual[0].commandIdMatches?.length);
});
test('filter modifiers are matched with complete term', async () => {
testObject = instantiationService.createInstance(KeybindingsEditorModel, OperatingSystem.Macintosh);
const command = `command.${uuid.generateUuid()}`;
const expected = aResolvedKeybindingItem({ command, firstPart: { keyCode: KeyCode.Escape, modifiers: { altKey: true } }, isDefault: false });
prepareKeybindingService(expected, aResolvedKeybindingItem({ command: 'some_command', firstPart: { keyCode: KeyCode.Escape }, isDefault: false }));
await testObject.resolve(new Map<string, string>());
const actual = testObject.fetch('alt').filter(element => element.keybindingItem.command === command);
assert.equal(1, actual.length);
assert.deepEqual(actual[0].keybindingMatches!.firstPart, { altKey: true });
});
function prepareKeybindingService(...keybindingItems: ResolvedKeybindingItem[]): ResolvedKeybindingItem[] { function prepareKeybindingService(...keybindingItems: ResolvedKeybindingItem[]): ResolvedKeybindingItem[] {
instantiationService.stub(IKeybindingService, 'getKeybindings', () => keybindingItems); instantiationService.stub(IKeybindingService, 'getKeybindings', () => keybindingItems);
instantiationService.stub(IKeybindingService, 'getDefaultKeybindings', () => keybindingItems); instantiationService.stub(IKeybindingService, 'getDefaultKeybindings', () => keybindingItems);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册