未验证 提交 87d09c2e 编写于 作者: A Alex Dima

Fixes #126306: Use the global context key service when computing primary keybinding for a command

上级 f1330007
...@@ -111,7 +111,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK ...@@ -111,7 +111,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
} }
public lookupKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybinding | undefined { 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) { if (!result) {
return undefined; return undefined;
} }
......
...@@ -247,15 +247,23 @@ export class KeybindingResolver { ...@@ -247,15 +247,23 @@ export class KeybindingResolver {
return result; return result;
} }
public lookupPrimaryKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybindingItem | null { public lookupPrimaryKeybinding(commandId: string, context: IContextKeyService): ResolvedKeybindingItem | null {
let items = this._lookupMap.get(commandId); const items = this._lookupMap.get(commandId);
if (typeof items === 'undefined' || items.length === 0) { if (typeof items === 'undefined' || items.length === 0) {
return null; 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 && return items[items.length - 1];
Array.from(items).reverse().find(item => context.contextMatchesRules(item.when));
return itemMatchingContext ?? items[items.length - 1];
} }
public resolve(context: IContext, currentChord: string | null, keypress: string): IResolveResult | null { public resolve(context: IContext, currentChord: string | null, keypress: string): IResolveResult | null {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册