mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 02:32:35 -05:00
Vscode merge (#4582)
* Merge from vscode 37cb23d3dd4f9433d56d4ba5ea3203580719a0bd * fix issues with merges * bump node version in azpipe * replace license headers * remove duplicate launch task * fix build errors * fix build errors * fix tslint issues * working through package and linux build issues * more work * wip * fix packaged builds * working through linux build errors * wip * wip * wip * fix mac and linux file limits * iterate linux pipeline * disable editor typing * revert series to parallel * remove optimize vscode from linux * fix linting issues * revert testing change * add work round for new node * readd packaging for extensions * fix issue with angular not resolving decorator dependencies
This commit is contained in:
@@ -17,6 +17,7 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { withNullAsUndefined } from 'vs/base/common/types';
|
||||
|
||||
interface CurrentChord {
|
||||
keypress: string;
|
||||
@@ -70,6 +71,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
|
||||
public abstract resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[];
|
||||
public abstract resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding;
|
||||
public abstract resolveUserBinding(userBinding: string): ResolvedKeybinding[];
|
||||
public abstract _dumpDebugInfo(): string;
|
||||
|
||||
public getDefaultKeybindingsContent(): string {
|
||||
return '';
|
||||
@@ -98,7 +100,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
|
||||
if (!result) {
|
||||
return undefined;
|
||||
}
|
||||
return result.resolvedKeybinding || undefined;
|
||||
return withNullAsUndefined(result.resolvedKeybinding);
|
||||
}
|
||||
|
||||
public dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean {
|
||||
|
||||
78
src/vs/platform/keybinding/common/baseResolvedKeybinding.ts
Normal file
78
src/vs/platform/keybinding/common/baseResolvedKeybinding.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { OperatingSystem } from 'vs/base/common/platform';
|
||||
import { illegalArgument } from 'vs/base/common/errors';
|
||||
import { Modifiers, UILabelProvider, AriaLabelProvider, ElectronAcceleratorLabelProvider, UserSettingsLabelProvider } from 'vs/base/common/keybindingLabels';
|
||||
import { ResolvedKeybinding, ResolvedKeybindingPart } from 'vs/base/common/keyCodes';
|
||||
|
||||
export abstract class BaseResolvedKeybinding<T extends Modifiers> extends ResolvedKeybinding {
|
||||
|
||||
protected readonly _os: OperatingSystem;
|
||||
protected readonly _parts: T[];
|
||||
|
||||
constructor(os: OperatingSystem, parts: T[]) {
|
||||
super();
|
||||
if (parts.length === 0) {
|
||||
throw illegalArgument(`parts`);
|
||||
}
|
||||
this._os = os;
|
||||
this._parts = parts;
|
||||
}
|
||||
|
||||
public getLabel(): string | null {
|
||||
return UILabelProvider.toLabel(this._os, this._parts, (keybinding) => this._getLabel(keybinding));
|
||||
}
|
||||
|
||||
public getAriaLabel(): string | null {
|
||||
return AriaLabelProvider.toLabel(this._os, this._parts, (keybinding) => this._getAriaLabel(keybinding));
|
||||
}
|
||||
|
||||
public getElectronAccelerator(): string | null {
|
||||
if (this._parts.length > 1) {
|
||||
// Electron cannot handle chords
|
||||
return null;
|
||||
}
|
||||
return ElectronAcceleratorLabelProvider.toLabel(this._os, this._parts, (keybinding) => this._getElectronAccelerator(keybinding));
|
||||
}
|
||||
|
||||
public getUserSettingsLabel(): string | null {
|
||||
return UserSettingsLabelProvider.toLabel(this._os, this._parts, (keybinding) => this._getUserSettingsLabel(keybinding));
|
||||
}
|
||||
|
||||
public isWYSIWYG(): boolean {
|
||||
return this._parts.every((keybinding) => this._isWYSIWYG(keybinding));
|
||||
}
|
||||
|
||||
public isChord(): boolean {
|
||||
return (this._parts.length > 1);
|
||||
}
|
||||
|
||||
public getParts(): ResolvedKeybindingPart[] {
|
||||
return this._parts.map((keybinding) => this._getPart(keybinding));
|
||||
}
|
||||
|
||||
private _getPart(keybinding: T): ResolvedKeybindingPart {
|
||||
return new ResolvedKeybindingPart(
|
||||
keybinding.ctrlKey,
|
||||
keybinding.shiftKey,
|
||||
keybinding.altKey,
|
||||
keybinding.metaKey,
|
||||
this._getLabel(keybinding),
|
||||
this._getAriaLabel(keybinding)
|
||||
);
|
||||
}
|
||||
|
||||
public getDispatchParts(): (string | null)[] {
|
||||
return this._parts.map((keybinding) => this._getDispatchPart(keybinding));
|
||||
}
|
||||
|
||||
protected abstract _getLabel(keybinding: T): string | null;
|
||||
protected abstract _getAriaLabel(keybinding: T): string | null;
|
||||
protected abstract _getElectronAccelerator(keybinding: T): string | null;
|
||||
protected abstract _getUserSettingsLabel(keybinding: T): string | null;
|
||||
protected abstract _isWYSIWYG(keybinding: T): boolean;
|
||||
protected abstract _getDispatchPart(keybinding: T): string | null;
|
||||
}
|
||||
@@ -28,6 +28,8 @@ export interface IKeybindingEvent {
|
||||
}
|
||||
|
||||
export interface IKeyboardEvent {
|
||||
readonly _standardKeyboardEventBrand: true;
|
||||
|
||||
readonly ctrlKey: boolean;
|
||||
readonly shiftKey: boolean;
|
||||
readonly altKey: boolean;
|
||||
@@ -89,5 +91,7 @@ export interface IKeybindingService {
|
||||
* text box. *Note* that the results of this function can be incorrect.
|
||||
*/
|
||||
mightProducePrintableCharacter(event: IKeyboardEvent): boolean;
|
||||
|
||||
_dumpDebugInfo(): string;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,12 +40,13 @@ export class KeybindingResolver {
|
||||
this._keybindings = KeybindingResolver.combine(defaultKeybindings, overrides);
|
||||
for (let i = 0, len = this._keybindings.length; i < len; i++) {
|
||||
let k = this._keybindings[i];
|
||||
if (k.keypressFirstPart === null) {
|
||||
if (k.keypressParts.length === 0) {
|
||||
// unbound
|
||||
continue;
|
||||
}
|
||||
|
||||
this._addKeyPress(k.keypressFirstPart, k);
|
||||
// TODO@chords
|
||||
this._addKeyPress(k.keypressParts[0], k);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +54,12 @@ export class KeybindingResolver {
|
||||
if (defaultKb.command !== command) {
|
||||
return false;
|
||||
}
|
||||
if (keypressFirstPart && defaultKb.keypressFirstPart !== keypressFirstPart) {
|
||||
// TODO@chords
|
||||
if (keypressFirstPart && defaultKb.keypressParts[0] !== keypressFirstPart) {
|
||||
return false;
|
||||
}
|
||||
if (keypressChordPart && defaultKb.keypressChordPart !== keypressChordPart) {
|
||||
// TODO@chords
|
||||
if (keypressChordPart && defaultKb.keypressParts[1] !== keypressChordPart) {
|
||||
return false;
|
||||
}
|
||||
if (when) {
|
||||
@@ -84,8 +87,9 @@ export class KeybindingResolver {
|
||||
}
|
||||
|
||||
const command = override.command.substr(1);
|
||||
const keypressFirstPart = override.keypressFirstPart;
|
||||
const keypressChordPart = override.keypressChordPart;
|
||||
// TODO@chords
|
||||
const keypressFirstPart = override.keypressParts[0];
|
||||
const keypressChordPart = override.keypressParts[1];
|
||||
const when = override.when;
|
||||
for (let j = defaults.length - 1; j >= 0; j--) {
|
||||
if (this._isTargetedForRemoval(defaults[j], keypressFirstPart, keypressChordPart, command, when)) {
|
||||
@@ -114,10 +118,11 @@ export class KeybindingResolver {
|
||||
continue;
|
||||
}
|
||||
|
||||
const conflictIsChord = (conflict.keypressChordPart !== null);
|
||||
const itemIsChord = (item.keypressChordPart !== null);
|
||||
const conflictIsChord = (conflict.keypressParts.length > 1);
|
||||
const itemIsChord = (item.keypressParts.length > 1);
|
||||
|
||||
if (conflictIsChord && itemIsChord && conflict.keypressChordPart !== item.keypressChordPart) {
|
||||
// TODO@chords
|
||||
if (conflictIsChord && itemIsChord && conflict.keypressParts[1] !== item.keypressParts[1]) {
|
||||
// The conflict only shares the chord start with this command
|
||||
continue;
|
||||
}
|
||||
@@ -247,7 +252,8 @@ export class KeybindingResolver {
|
||||
lookupMap = [];
|
||||
for (let i = 0, len = candidates.length; i < len; i++) {
|
||||
let candidate = candidates[i];
|
||||
if (candidate.keypressChordPart === keypress) {
|
||||
// TODO@chords
|
||||
if (candidate.keypressParts[1] === keypress) {
|
||||
lookupMap.push(candidate);
|
||||
}
|
||||
}
|
||||
@@ -266,7 +272,8 @@ export class KeybindingResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (currentChord === null && result.keypressChordPart !== null) {
|
||||
// TODO@chords
|
||||
if (currentChord === null && result.keypressParts.length > 1 && result.keypressParts[1] !== null) {
|
||||
return {
|
||||
enterChord: true,
|
||||
commandId: null,
|
||||
@@ -307,29 +314,31 @@ export class KeybindingResolver {
|
||||
public static getAllUnboundCommands(boundCommands: Map<string, boolean>): string[] {
|
||||
const unboundCommands: string[] = [];
|
||||
const seenMap: Map<string, boolean> = new Map<string, boolean>();
|
||||
const addCommand = id => {
|
||||
const addCommand = (id: string, includeCommandWithArgs: boolean) => {
|
||||
if (seenMap.has(id)) {
|
||||
return;
|
||||
}
|
||||
seenMap.set(id);
|
||||
seenMap.set(id, true);
|
||||
if (id[0] === '_' || id.indexOf('vscode.') === 0) { // private command
|
||||
return;
|
||||
}
|
||||
if (boundCommands.get(id) === true) {
|
||||
return;
|
||||
}
|
||||
const command = CommandsRegistry.getCommand(id);
|
||||
if (command && typeof command.description === 'object'
|
||||
&& isNonEmptyArray((<ICommandHandlerDescription>command.description).args)) { // command with args
|
||||
return;
|
||||
if (!includeCommandWithArgs) {
|
||||
const command = CommandsRegistry.getCommand(id);
|
||||
if (command && typeof command.description === 'object'
|
||||
&& isNonEmptyArray((<ICommandHandlerDescription>command.description).args)) { // command with args
|
||||
return;
|
||||
}
|
||||
}
|
||||
unboundCommands.push(id);
|
||||
};
|
||||
for (const id in MenuRegistry.getCommands()) {
|
||||
addCommand(id);
|
||||
addCommand(id, true);
|
||||
}
|
||||
for (const id in CommandsRegistry.getCommands()) {
|
||||
addCommand(id);
|
||||
addCommand(id, false);
|
||||
}
|
||||
|
||||
return unboundCommands;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { KeyCode, Keybinding, KeybindingType, SimpleKeybinding, createKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { KeyCode, Keybinding, SimpleKeybinding, createKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { OS, OperatingSystem } from 'vs/base/common/platform';
|
||||
import { CommandsRegistry, ICommandHandler, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
@@ -19,7 +19,7 @@ export interface IKeybindingItem {
|
||||
}
|
||||
|
||||
export interface IKeybindings {
|
||||
primary: number;
|
||||
primary?: number;
|
||||
secondary?: number[];
|
||||
win?: {
|
||||
primary: number;
|
||||
@@ -210,11 +210,7 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry {
|
||||
|
||||
private _registerDefaultKeybinding(keybinding: Keybinding, commandId: string, commandArgs: any, weight1: number, weight2: number, when: ContextKeyExpr | null | undefined): void {
|
||||
if (OS === OperatingSystem.Windows) {
|
||||
if (keybinding.type === KeybindingType.Chord) {
|
||||
this._assertNoCtrlAlt(keybinding.firstPart, commandId);
|
||||
} else {
|
||||
this._assertNoCtrlAlt(keybinding, commandId);
|
||||
}
|
||||
this._assertNoCtrlAlt(keybinding.parts[0], commandId);
|
||||
}
|
||||
this._coreKeybindings.push({
|
||||
keybinding: keybinding,
|
||||
|
||||
@@ -11,8 +11,7 @@ export class ResolvedKeybindingItem {
|
||||
_resolvedKeybindingItemBrand: void;
|
||||
|
||||
public readonly resolvedKeybinding: ResolvedKeybinding | null;
|
||||
public readonly keypressFirstPart: string | null;
|
||||
public readonly keypressChordPart: string | null;
|
||||
public readonly keypressParts: string[];
|
||||
public readonly bubble: boolean;
|
||||
public readonly command: string | null;
|
||||
public readonly commandArgs: any;
|
||||
@@ -21,14 +20,7 @@ export class ResolvedKeybindingItem {
|
||||
|
||||
constructor(resolvedKeybinding: ResolvedKeybinding | null, command: string | null, commandArgs: any, when: ContextKeyExpr | null, isDefault: boolean) {
|
||||
this.resolvedKeybinding = resolvedKeybinding;
|
||||
if (resolvedKeybinding) {
|
||||
let [keypressFirstPart, keypressChordPart] = resolvedKeybinding.getDispatchParts();
|
||||
this.keypressFirstPart = keypressFirstPart;
|
||||
this.keypressChordPart = keypressChordPart;
|
||||
} else {
|
||||
this.keypressFirstPart = null;
|
||||
this.keypressChordPart = null;
|
||||
}
|
||||
this.keypressParts = resolvedKeybinding ? removeElementsAfterNulls(resolvedKeybinding.getDispatchParts()) : [];
|
||||
this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);
|
||||
this.command = this.bubble ? command!.substr(1) : command;
|
||||
this.commandArgs = commandArgs;
|
||||
@@ -36,3 +28,16 @@ export class ResolvedKeybindingItem {
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
}
|
||||
|
||||
export function removeElementsAfterNulls<T>(arr: (T | null)[]): T[] {
|
||||
let result: T[] = [];
|
||||
for (let i = 0, len = arr.length; i < len; i++) {
|
||||
const element = arr[i];
|
||||
if (!element) {
|
||||
// stop processing at first encountered null
|
||||
return result;
|
||||
}
|
||||
result.push(element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3,31 +3,17 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { KeyCode, KeyCodeUtils, Keybinding, KeybindingType, ResolvedKeybinding, ResolvedKeybindingPart, SimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { AriaLabelProvider, ElectronAcceleratorLabelProvider, UILabelProvider, UserSettingsLabelProvider } from 'vs/base/common/keybindingLabels';
|
||||
import { KeyCode, KeyCodeUtils, Keybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { OperatingSystem } from 'vs/base/common/platform';
|
||||
import { BaseResolvedKeybinding } from 'vs/platform/keybinding/common/baseResolvedKeybinding';
|
||||
|
||||
/**
|
||||
* Do not instantiate. Use KeybindingService to get a ResolvedKeybinding seeded with information about the current kb layout.
|
||||
*/
|
||||
export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
export class USLayoutResolvedKeybinding extends BaseResolvedKeybinding<SimpleKeybinding> {
|
||||
|
||||
private readonly _os: OperatingSystem;
|
||||
private readonly _firstPart: SimpleKeybinding;
|
||||
private readonly _chordPart: SimpleKeybinding | null;
|
||||
|
||||
constructor(actual: Keybinding, OS: OperatingSystem) {
|
||||
super();
|
||||
this._os = OS;
|
||||
if (!actual) {
|
||||
throw new Error(`Invalid USLayoutResolvedKeybinding`);
|
||||
} else if (actual.type === KeybindingType.Chord) {
|
||||
this._firstPart = actual.firstPart;
|
||||
this._chordPart = actual.chordPart;
|
||||
} else {
|
||||
this._firstPart = actual;
|
||||
this._chordPart = null;
|
||||
}
|
||||
constructor(actual: Keybinding, os: OperatingSystem) {
|
||||
super(os, actual.parts);
|
||||
}
|
||||
|
||||
private _keyCodeToUILabel(keyCode: KeyCode): string {
|
||||
@@ -46,38 +32,20 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return KeyCodeUtils.toString(keyCode);
|
||||
}
|
||||
|
||||
private _getUILabelForKeybinding(keybinding: SimpleKeybinding | null): string | null {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
protected _getLabel(keybinding: SimpleKeybinding): string | null {
|
||||
if (keybinding.isDuplicateModifierCase()) {
|
||||
return '';
|
||||
}
|
||||
return this._keyCodeToUILabel(keybinding.keyCode);
|
||||
}
|
||||
|
||||
public getLabel(): string | null {
|
||||
let firstPart = this._getUILabelForKeybinding(this._firstPart);
|
||||
let chordPart = this._getUILabelForKeybinding(this._chordPart);
|
||||
return UILabelProvider.toLabel(this._firstPart, firstPart, this._chordPart, chordPart, this._os);
|
||||
}
|
||||
|
||||
private _getAriaLabelForKeybinding(keybinding: SimpleKeybinding | null): string | null {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
protected _getAriaLabel(keybinding: SimpleKeybinding): string | null {
|
||||
if (keybinding.isDuplicateModifierCase()) {
|
||||
return '';
|
||||
}
|
||||
return KeyCodeUtils.toString(keybinding.keyCode);
|
||||
}
|
||||
|
||||
public getAriaLabel(): string | null {
|
||||
let firstPart = this._getAriaLabelForKeybinding(this._firstPart);
|
||||
let chordPart = this._getAriaLabelForKeybinding(this._chordPart);
|
||||
return AriaLabelProvider.toLabel(this._firstPart, firstPart, this._chordPart, chordPart, this._os);
|
||||
}
|
||||
|
||||
private _keyCodeToElectronAccelerator(keyCode: KeyCode): string | null {
|
||||
if (keyCode >= KeyCode.NUMPAD_0 && keyCode <= KeyCode.NUMPAD_DIVIDE) {
|
||||
// Electron cannot handle numpad keys
|
||||
@@ -98,73 +66,27 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
|
||||
return KeyCodeUtils.toString(keyCode);
|
||||
}
|
||||
|
||||
private _getElectronAcceleratorLabelForKeybinding(keybinding: SimpleKeybinding | null): string | null {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
protected _getElectronAccelerator(keybinding: SimpleKeybinding): string | null {
|
||||
if (keybinding.isDuplicateModifierCase()) {
|
||||
return null;
|
||||
}
|
||||
return this._keyCodeToElectronAccelerator(keybinding.keyCode);
|
||||
}
|
||||
|
||||
public getElectronAccelerator(): string | null {
|
||||
if (this._chordPart !== null) {
|
||||
// Electron cannot handle chords
|
||||
return null;
|
||||
}
|
||||
|
||||
let firstPart = this._getElectronAcceleratorLabelForKeybinding(this._firstPart);
|
||||
return ElectronAcceleratorLabelProvider.toLabel(this._firstPart, firstPart, null, null, this._os);
|
||||
}
|
||||
|
||||
private _getUserSettingsLabelForKeybinding(keybinding: SimpleKeybinding | null): string | null {
|
||||
if (!keybinding) {
|
||||
return null;
|
||||
}
|
||||
protected _getUserSettingsLabel(keybinding: SimpleKeybinding): string | null {
|
||||
if (keybinding.isDuplicateModifierCase()) {
|
||||
return '';
|
||||
}
|
||||
return KeyCodeUtils.toUserSettingsUS(keybinding.keyCode);
|
||||
}
|
||||
|
||||
public getUserSettingsLabel(): string | null {
|
||||
let firstPart = this._getUserSettingsLabelForKeybinding(this._firstPart);
|
||||
let chordPart = this._getUserSettingsLabelForKeybinding(this._chordPart);
|
||||
let result = UserSettingsLabelProvider.toLabel(this._firstPart, firstPart, this._chordPart, chordPart, this._os);
|
||||
const result = KeyCodeUtils.toUserSettingsUS(keybinding.keyCode);
|
||||
return (result ? result.toLowerCase() : result);
|
||||
}
|
||||
|
||||
public isWYSIWYG(): boolean {
|
||||
protected _isWYSIWYG(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public isChord(): boolean {
|
||||
return (this._chordPart ? true : false);
|
||||
}
|
||||
|
||||
public getParts(): [ResolvedKeybindingPart, ResolvedKeybindingPart | null] {
|
||||
return [
|
||||
this._toResolvedKeybindingPart(this._firstPart),
|
||||
this._chordPart ? this._toResolvedKeybindingPart(this._chordPart) : null
|
||||
];
|
||||
}
|
||||
|
||||
private _toResolvedKeybindingPart(keybinding: SimpleKeybinding): ResolvedKeybindingPart {
|
||||
return new ResolvedKeybindingPart(
|
||||
keybinding.ctrlKey,
|
||||
keybinding.shiftKey,
|
||||
keybinding.altKey,
|
||||
keybinding.metaKey,
|
||||
this._getUILabelForKeybinding(keybinding),
|
||||
this._getAriaLabelForKeybinding(keybinding)
|
||||
);
|
||||
}
|
||||
|
||||
public getDispatchParts(): [string | null, string | null] {
|
||||
let firstPart = this._firstPart ? USLayoutResolvedKeybinding.getDispatchStr(this._firstPart) : null;
|
||||
let chordPart = this._chordPart ? USLayoutResolvedKeybinding.getDispatchStr(this._chordPart) : null;
|
||||
return [firstPart, chordPart];
|
||||
protected _getDispatchPart(keybinding: SimpleKeybinding): string | null {
|
||||
return USLayoutResolvedKeybinding.getDispatchStr(keybinding);
|
||||
}
|
||||
|
||||
public static getDispatchStr(keybinding: SimpleKeybinding): string | null {
|
||||
|
||||
@@ -61,7 +61,7 @@ suite('AbstractKeybindingService', () => {
|
||||
keyboardEvent.altKey,
|
||||
keyboardEvent.metaKey,
|
||||
keyboardEvent.keyCode
|
||||
);
|
||||
).toChord();
|
||||
return this.resolveKeybinding(keybinding)[0];
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ suite('AbstractKeybindingService', () => {
|
||||
public testDispatch(kb: number): boolean {
|
||||
const keybinding = createSimpleKeybinding(kb, OS);
|
||||
return this._dispatch({
|
||||
_standardKeyboardEventBrand: true,
|
||||
ctrlKey: keybinding.ctrlKey,
|
||||
shiftKey: keybinding.shiftKey,
|
||||
altKey: keybinding.altKey,
|
||||
@@ -80,6 +81,10 @@ suite('AbstractKeybindingService', () => {
|
||||
code: null!
|
||||
}, null!);
|
||||
}
|
||||
|
||||
public _dumpDebugInfo(): string {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
let createTestKeybindingService: (items: ResolvedKeybindingItem[], contextValue?: any) => TestKeybindingService = null!;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as assert from 'assert';
|
||||
import { KeyChord, KeyCode, KeyMod, KeybindingType, SimpleKeybinding, createKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { KeyChord, KeyCode, KeyMod, SimpleKeybinding, createKeybinding, createSimpleKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { OS } from 'vs/base/common/platform';
|
||||
import { ContextKeyAndExpr, ContextKeyExpr, IContext } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
@@ -37,7 +37,7 @@ suite('KeybindingResolver', () => {
|
||||
|
||||
test('resolve key', function () {
|
||||
let keybinding = KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z;
|
||||
let runtimeKeybinding = createKeybinding(keybinding, OS);
|
||||
let runtimeKeybinding = createSimpleKeybinding(keybinding, OS);
|
||||
let contextRules = ContextKeyExpr.equals('bar', 'baz');
|
||||
let keybindingItem = kbItem(keybinding, 'yes', null, contextRules, true);
|
||||
|
||||
@@ -45,19 +45,19 @@ suite('KeybindingResolver', () => {
|
||||
assert.equal(KeybindingResolver.contextMatchesRules(createContext({ bar: 'bz' }), contextRules), false);
|
||||
|
||||
let resolver = new KeybindingResolver([keybindingItem], []);
|
||||
assert.equal(resolver.resolve(createContext({ bar: 'baz' }), null, getDispatchStr(<SimpleKeybinding>runtimeKeybinding))!.commandId, 'yes');
|
||||
assert.equal(resolver.resolve(createContext({ bar: 'bz' }), null, getDispatchStr(<SimpleKeybinding>runtimeKeybinding)), null);
|
||||
assert.equal(resolver.resolve(createContext({ bar: 'baz' }), null, getDispatchStr(runtimeKeybinding))!.commandId, 'yes');
|
||||
assert.equal(resolver.resolve(createContext({ bar: 'bz' }), null, getDispatchStr(runtimeKeybinding)), null);
|
||||
});
|
||||
|
||||
test('resolve key with arguments', function () {
|
||||
let commandArgs = { text: 'no' };
|
||||
let keybinding = KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z;
|
||||
let runtimeKeybinding = createKeybinding(keybinding, OS);
|
||||
let runtimeKeybinding = createSimpleKeybinding(keybinding, OS);
|
||||
let contextRules = ContextKeyExpr.equals('bar', 'baz');
|
||||
let keybindingItem = kbItem(keybinding, 'yes', commandArgs, contextRules, true);
|
||||
|
||||
let resolver = new KeybindingResolver([keybindingItem], []);
|
||||
assert.equal(resolver.resolve(createContext({ bar: 'baz' }), null, getDispatchStr(<SimpleKeybinding>runtimeKeybinding))!.commandArgs, commandArgs);
|
||||
assert.equal(resolver.resolve(createContext({ bar: 'baz' }), null, getDispatchStr(runtimeKeybinding))!.commandArgs, commandArgs);
|
||||
});
|
||||
|
||||
test('KeybindingResolver.combine simple 1', function () {
|
||||
@@ -346,24 +346,24 @@ suite('KeybindingResolver', () => {
|
||||
let testResolve = (ctx: IContext, _expectedKey: number, commandId: string) => {
|
||||
const expectedKey = createKeybinding(_expectedKey, OS)!;
|
||||
|
||||
if (expectedKey.type === KeybindingType.Chord) {
|
||||
let firstPart = getDispatchStr(expectedKey.firstPart);
|
||||
let chordPart = getDispatchStr(expectedKey.chordPart);
|
||||
|
||||
let result = resolver.resolve(ctx, null, firstPart)!;
|
||||
assert.ok(result !== null, 'Enters chord for ' + commandId);
|
||||
assert.equal(result.commandId, null, 'Enters chord for ' + commandId);
|
||||
assert.equal(result.enterChord, true, 'Enters chord for ' + commandId);
|
||||
|
||||
result = resolver.resolve(ctx, firstPart, chordPart)!;
|
||||
assert.ok(result !== null, 'Enters chord for ' + commandId);
|
||||
assert.equal(result.commandId, commandId, 'Finds chorded command ' + commandId);
|
||||
assert.equal(result.enterChord, false, 'Finds chorded command ' + commandId);
|
||||
} else {
|
||||
let result = resolver.resolve(ctx, null, getDispatchStr(expectedKey))!;
|
||||
assert.ok(result !== null, 'Finds command ' + commandId);
|
||||
assert.equal(result.commandId, commandId, 'Finds command ' + commandId);
|
||||
assert.equal(result.enterChord, false, 'Finds command ' + commandId);
|
||||
let previousPart: (string | null) = null;
|
||||
for (let i = 0, len = expectedKey.parts.length; i < len; i++) {
|
||||
let part = getDispatchStr(expectedKey.parts[i]);
|
||||
let result = resolver.resolve(ctx, previousPart, part);
|
||||
if (i === len - 1) {
|
||||
// if it's the final part, then we should find a valid command,
|
||||
// and there should not be a chord.
|
||||
assert.ok(result !== null, `Enters chord for ${commandId} at part ${i}`);
|
||||
assert.equal(result!.commandId, commandId, `Enters chord for ${commandId} at part ${i}`);
|
||||
assert.equal(result!.enterChord, false, `Enters chord for ${commandId} at part ${i}`);
|
||||
} else {
|
||||
// if it's not the final part, then we should not find a valid command,
|
||||
// and there should be a chord.
|
||||
assert.ok(result !== null, `Enters chord for ${commandId} at part ${i}`);
|
||||
assert.equal(result!.commandId, null, `Enters chord for ${commandId} at part ${i}`);
|
||||
assert.equal(result!.enterChord, true, `Enters chord for ${commandId} at part ${i}`);
|
||||
}
|
||||
previousPart = part;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ export class MockKeybindingService implements IKeybindingService {
|
||||
keyboardEvent.metaKey,
|
||||
keyboardEvent.keyCode
|
||||
);
|
||||
return this.resolveKeybinding(keybinding)[0];
|
||||
return this.resolveKeybinding(keybinding.toChord())[0];
|
||||
}
|
||||
|
||||
public resolveUserBinding(userBinding: string): ResolvedKeybinding[] {
|
||||
@@ -132,4 +132,8 @@ export class MockKeybindingService implements IKeybindingService {
|
||||
public mightProducePrintableCharacter(e: IKeyboardEvent): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public _dumpDebugInfo(): string {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user