diff --git a/src/vs/platform/keybinding/common/abstractKeybindingService.ts b/src/vs/platform/keybinding/common/abstractKeybindingService.ts index de7210a736ffb6bc34636e288a84b6e8161b9ef0..56122f34f20d25cd9c698b181a735d14706b2789 100644 --- a/src/vs/platform/keybinding/common/abstractKeybindingService.ts +++ b/src/vs/platform/keybinding/common/abstractKeybindingService.ts @@ -111,7 +111,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK } public lookupKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybinding | undefined { - const result = this._getResolver().lookupPrimaryKeybinding(commandId, context); + const result = this._getResolver().lookupPrimaryKeybinding(commandId, context || this._contextKeyService); if (!result) { return undefined; } diff --git a/src/vs/platform/keybinding/common/keybindingResolver.ts b/src/vs/platform/keybinding/common/keybindingResolver.ts index db47d1155a1abfd542aff5fcdf09230be766a56f..fb0f8b17cfb0084746c51720107e01ea79e21fc9 100644 --- a/src/vs/platform/keybinding/common/keybindingResolver.ts +++ b/src/vs/platform/keybinding/common/keybindingResolver.ts @@ -247,15 +247,23 @@ export class KeybindingResolver { return result; } - public lookupPrimaryKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybindingItem | null { - let items = this._lookupMap.get(commandId); + public lookupPrimaryKeybinding(commandId: string, context: IContextKeyService): ResolvedKeybindingItem | null { + const items = this._lookupMap.get(commandId); if (typeof items === 'undefined' || items.length === 0) { return null; } + if (items.length === 1) { + return items[0]; + } + + for (let i = items.length - 1; i >= 0; i--) { + const item = items[i]; + if (context.contextMatchesRules(item.when)) { + return item; + } + } - const itemMatchingContext = context && - Array.from(items).reverse().find(item => context.contextMatchesRules(item.when)); - return itemMatchingContext ?? items[items.length - 1]; + return items[items.length - 1]; } public resolve(context: IContext, currentChord: string | null, keypress: string): IResolveResult | null {