Merge from vscode e3c4990c67c40213af168300d1cfeb71d680f877 (#16569)

This commit is contained in:
Cory Rivera
2021-08-25 16:28:29 -07:00
committed by GitHub
parent ab1112bfb3
commit cb7b7da0a4
1752 changed files with 59525 additions and 33878 deletions

View File

@@ -24,6 +24,9 @@ interface CurrentChord {
label: string | null;
}
// Skip logging for high-frequency text editing commands
const HIGH_FREQ_COMMANDS = /^(cursor|delete)/;
export abstract class AbstractKeybindingService extends Disposable implements IKeybindingService {
public _serviceBrand: undefined;
@@ -107,8 +110,8 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
);
}
public lookupKeybinding(commandId: string): ResolvedKeybinding | undefined {
const result = this._getResolver().lookupPrimaryKeybinding(commandId);
public lookupKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybinding | undefined {
const result = this._getResolver().lookupPrimaryKeybinding(commandId, context);
if (!result) {
return undefined;
}
@@ -263,7 +266,9 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
} else {
this._commandService.executeCommand(resolveResult.commandId, resolveResult.commandArgs).then(undefined, err => this._notificationService.warn(err));
}
this._telemetryService.publicLog2<WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification>('workbenchActionExecuted', { id: resolveResult.commandId, from: 'keybinding' });
if (!HIGH_FREQ_COMMANDS.test(resolveResult.commandId)) {
this._telemetryService.publicLog2<WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification>('workbenchActionExecuted', { id: resolveResult.commandId, from: 'keybinding' });
}
}
return shouldPreventDefault;

View File

@@ -6,7 +6,7 @@
import { Event } from 'vs/base/common/event';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { Keybinding, KeyCode, ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
@@ -85,7 +85,7 @@ export interface IKeybindingService {
* Look up the preferred (last defined) keybinding for a command.
* @returns The preferred keybinding or null if the command is not bound.
*/
lookupKeybinding(commandId: string): ResolvedKeybinding | undefined;
lookupKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybinding | undefined;
getDefaultKeybindingsContent(): string;

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IContext, ContextKeyExpression, ContextKeyExprType } from 'vs/platform/contextkey/common/contextkey';
import { ContextKeyExpression, ContextKeyExprType, IContext, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
export interface IResolveResult {
@@ -183,10 +183,10 @@ export class KeybindingResolver {
* Returns true if it is provable `a` implies `b`.
*/
public static whenIsEntirelyIncluded(a: ContextKeyExpression | null | undefined, b: ContextKeyExpression | null | undefined): boolean {
if (!b) {
if (!b || b.type === ContextKeyExprType.True) {
return true;
}
if (!a) {
if (!a || a.type === ContextKeyExprType.True) {
return false;
}
@@ -247,13 +247,15 @@ export class KeybindingResolver {
return result;
}
public lookupPrimaryKeybinding(commandId: string): ResolvedKeybindingItem | null {
public lookupPrimaryKeybinding(commandId: string, context?: IContextKeyService): ResolvedKeybindingItem | null {
let items = this._lookupMap.get(commandId);
if (typeof items === 'undefined' || items.length === 0) {
return null;
}
return items[items.length - 1];
const itemMatchingContext = context &&
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 {

View File

@@ -193,16 +193,27 @@ suite('KeybindingResolver', () => {
});
test('contextIsEntirelyIncluded', () => {
const assertIsIncluded = (a: string | null, b: string | null) => {
assert.strictEqual(KeybindingResolver.whenIsEntirelyIncluded(ContextKeyExpr.deserialize(a), ContextKeyExpr.deserialize(b)), true);
const toContextKeyExpression = (expr: ContextKeyExpression | string | null) => {
if (typeof expr === 'string' || !expr) {
return ContextKeyExpr.deserialize(expr as string); // {{SQL CARBON EDIT}} Cast to string
}
return expr;
};
const assertIsNotIncluded = (a: string | null, b: string | null) => {
assert.strictEqual(KeybindingResolver.whenIsEntirelyIncluded(ContextKeyExpr.deserialize(a), ContextKeyExpr.deserialize(b)), false);
const assertIsIncluded = (a: ContextKeyExpression | string | null, b: ContextKeyExpression | string | null) => {
assert.strictEqual(KeybindingResolver.whenIsEntirelyIncluded(toContextKeyExpression(a), toContextKeyExpression(b)), true);
};
const assertIsNotIncluded = (a: ContextKeyExpression | string | null, b: ContextKeyExpression | string | null) => {
assert.strictEqual(KeybindingResolver.whenIsEntirelyIncluded(toContextKeyExpression(a), toContextKeyExpression(b)), false);
};
assertIsIncluded(null, null);
assertIsIncluded(null, ContextKeyExpr.true());
assertIsIncluded(ContextKeyExpr.true(), null);
assertIsIncluded(ContextKeyExpr.true(), ContextKeyExpr.true());
assertIsIncluded('key1', null);
assertIsIncluded('key1', '');
assertIsIncluded('key1', 'key1');
assertIsIncluded('key1', ContextKeyExpr.true());
assertIsIncluded('!key1', '');
assertIsIncluded('!key1', '!key1');
assertIsIncluded('key2', '');