提交 b71baf97 编写于 作者: A Alex Dima

Reduce usage of BinaryKeybindings

上级 1651e4f9
......@@ -40,7 +40,7 @@ declare module monaco {
#include(vs/base/common/cancellation): CancellationTokenSource, CancellationToken
#include(vs/base/common/uri): URI
#include(vs/editor/common/standalone/standaloneBase): KeyCode, KeyMod
#include(vs/base/common/keyCodes): Keybinding
#include(vs/base/common/keyCodes): SimpleKeybinding
#include(vs/base/common/htmlContent): MarkedString
#include(vs/base/browser/keyboardEvent): IKeyboardEvent
#include(vs/base/browser/mouseEvent): IMouseEvent
......
......@@ -5,7 +5,7 @@
'use strict';
import { Keybinding, KeyCode, KeyCodeUtils, KeyMod } from 'vs/base/common/keyCodes';
import { SimpleKeybinding, KeyCode, KeyCodeUtils, KeyMod } from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform';
import * as browser from 'vs/base/browser/browser';
......@@ -175,7 +175,7 @@ export interface IKeyboardEvent {
readonly metaKey: boolean;
readonly keyCode: KeyCode;
toKeybinding(): Keybinding;
toKeybinding(): SimpleKeybinding;
equals(keybinding: number): boolean;
preventDefault(): void;
......@@ -198,7 +198,7 @@ export class StandardKeyboardEvent implements IKeyboardEvent {
public readonly metaKey: boolean;
public readonly keyCode: KeyCode;
private _asKeybinding: Keybinding;
private _asKeybinding: SimpleKeybinding;
constructor(source: KeyboardEvent) {
let e = <KeyboardEvent>source;
......@@ -234,7 +234,7 @@ export class StandardKeyboardEvent implements IKeyboardEvent {
}
}
public toKeybinding(): Keybinding {
public toKeybinding(): SimpleKeybinding {
return this._asKeybinding;
}
......@@ -242,7 +242,7 @@ export class StandardKeyboardEvent implements IKeyboardEvent {
return this._asKeybinding.value === other;
}
private _computeKeybinding(): Keybinding {
private _computeKeybinding(): SimpleKeybinding {
let key = KeyCode.Unknown;
if (this.keyCode !== KeyCode.Ctrl && this.keyCode !== KeyCode.Shift && this.keyCode !== KeyCode.Alt && this.keyCode !== KeyCode.Meta) {
key = this.keyCode;
......@@ -263,6 +263,6 @@ export class StandardKeyboardEvent implements IKeyboardEvent {
}
result |= key;
return new Keybinding(result);
return new SimpleKeybinding(result);
}
}
......@@ -486,16 +486,32 @@ export class BinaryKeybindings {
}
}
export class Keybinding {
export function createKeybinding(keybinding: number): Keybinding {
if (BinaryKeybindings.hasChord(keybinding)) {
return new ChordKeybinding(keybinding);
}
return new SimpleKeybinding(keybinding);
}
public value: number;
export class SimpleKeybinding {
public readonly value: number;
constructor(keybinding: number) {
this.value = keybinding;
}
/**
* @internal
*/
public isChord(): this is ChordKeybinding {
return false;
}
/**
* @internal
*/
public equals(other: Keybinding): boolean {
return this.value === other.value;
return (other && this.value === other.value);
}
public hasCtrlCmd(): boolean {
......@@ -522,3 +538,29 @@ export class Keybinding {
return BinaryKeybindings.extractKeyCode(this.value);
}
}
export class ChordKeybinding {
public readonly value: number;
constructor(keybinding: number) {
this.value = keybinding;
}
public isChord(): this is ChordKeybinding {
return true;
}
public equals(other: Keybinding): boolean {
return (other && this.value === other.value);
}
public extractFirstPart(): SimpleKeybinding {
return new SimpleKeybinding(BinaryKeybindings.extractFirstPart(this.value));
}
public extractChordPart(): SimpleKeybinding {
return new SimpleKeybinding(BinaryKeybindings.extractChordPart(this.value));
}
}
export type Keybinding = SimpleKeybinding | ChordKeybinding;
......@@ -248,6 +248,10 @@ export class QuickOpenWidget implements IModelProvider {
// Select element when keys are pressed that signal it
const quickNavKeys = this.quickNavigateConfiguration.keybindings;
const wasTriggerKeyPressed = keyCode === KeyCode.Enter || quickNavKeys.some((k) => {
if (k.isChord()) {
return false;
}
if (k.hasShift() && keyCode === KeyCode.Shift) {
if (keyboardEvent.ctrlKey || keyboardEvent.altKey || keyboardEvent.metaKey) {
return false; // this is an optimistic check for the shift key being used to navigate back in quick open
......
......@@ -5,7 +5,7 @@
'use strict';
import { Emitter } from 'vs/base/common/event';
import { Keybinding, KeyMod as ConstKeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { SimpleKeybinding, KeyMod as ConstKeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection, SelectionDirection } from 'vs/editor/common/core/selection';
......@@ -224,7 +224,7 @@ export function createMonacoBaseAPI(): typeof monaco {
Emitter: Emitter,
KeyCode: KeyCode,
KeyMod: KeyMod,
Keybinding: <any>Keybinding,
SimpleKeybinding: <any>SimpleKeybinding,
Position: Position,
Range: Range,
Selection: Selection,
......
......@@ -9,7 +9,7 @@ import 'vs/css!./defineKeybinding';
import * as nls from 'vs/nls';
import { RunOnceScheduler } from 'vs/base/common/async';
import { MarkedString } from 'vs/base/common/htmlContent';
import { Keybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { createKeybinding, Keybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { KeybindingLabels } from 'vs/base/common/keybinding';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import * as dom from 'vs/base/browser/dom';
......@@ -165,7 +165,7 @@ export class DefineKeybindingController implements editorCommon.IEditorContribut
let numKeybinding = IOSupport.readKeybinding(strKeybinding);
let keybinding = new Keybinding(numKeybinding);
let keybinding = createKeybinding(numKeybinding);
return {
strKeybinding: strKeybinding,
......
......@@ -9,7 +9,7 @@ import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyServ
import { SimpleConfigurationService, SimpleMessageService, StandaloneKeybindingService, StandaloneCommandService } from 'vs/editor/browser/standalone/simpleServices';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { Keybinding, KeyCode } from 'vs/base/common/keyCodes';
import { SimpleKeybinding, KeyCode } from 'vs/base/common/keyCodes';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
suite('StandaloneKeybindingService', () => {
......@@ -46,7 +46,7 @@ suite('StandaloneKeybindingService', () => {
}, null);
keybindingService.dispatch(<any>{
toKeybinding: () => new Keybinding(KeyCode.F9),
toKeybinding: () => new SimpleKeybinding(KeyCode.F9),
preventDefault: () => { }
});
......
......@@ -363,10 +363,9 @@ declare module monaco {
static chord(firstPart: number, secondPart: number): number;
}
export class Keybinding {
value: number;
export class SimpleKeybinding {
readonly value: number;
constructor(keybinding: number);
equals(other: Keybinding): boolean;
hasCtrlCmd(): boolean;
hasShift(): boolean;
hasAlt(): boolean;
......@@ -392,7 +391,7 @@ declare module monaco {
readonly altKey: boolean;
readonly metaKey: boolean;
readonly keyCode: KeyCode;
toKeybinding(): Keybinding;
toKeybinding(): SimpleKeybinding;
equals(keybinding: number): boolean;
preventDefault(): void;
stopPropagation(): void;
......
......@@ -6,7 +6,7 @@
import * as nls from 'vs/nls';
import { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { Keybinding } from 'vs/base/common/keyCodes';
import { SimpleKeybinding, Keybinding } from 'vs/base/common/keyCodes';
import { KeybindingLabels } from 'vs/base/common/keybinding';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import Severity from 'vs/base/common/severity';
......@@ -24,7 +24,7 @@ export abstract class AbstractKeybindingService implements IKeybindingService {
protected toDispose: IDisposable[] = [];
private _currentChord: number;
private _currentChord: SimpleKeybinding;
private _currentChordStatusMessage: IDisposable;
protected _onDidUpdateKeybindings: Emitter<IKeybindingEvent>;
......@@ -44,7 +44,7 @@ export abstract class AbstractKeybindingService implements IKeybindingService {
this._statusService = statusService;
this._messageService = messageService;
this._currentChord = 0;
this._currentChord = null;
this._currentChordStatusMessage = null;
this._onDidUpdateKeybindings = new Emitter<IKeybindingEvent>();
this.toDispose.push(this._onDidUpdateKeybindings);
......@@ -112,16 +112,16 @@ export abstract class AbstractKeybindingService implements IKeybindingService {
return '// ' + nls.localize('unboundCommands', "Here are other available commands: ") + '\n// - ' + pretty;
}
public resolve(keybinding: Keybinding, target: IContextKeyServiceTarget): IResolveResult {
public resolve(keybinding: SimpleKeybinding, target: IContextKeyServiceTarget): IResolveResult {
if (keybinding.isModifierKey()) {
return null;
}
const contextValue = this._contextKeyService.getContextValue(target);
return this._getResolver().resolve(contextValue, this._currentChord, keybinding.value);
return this._getResolver().resolve(contextValue, this._currentChord, keybinding);
}
protected _dispatch(keybinding: Keybinding, target: IContextKeyServiceTarget): boolean {
protected _dispatch(keybinding: SimpleKeybinding, target: IContextKeyServiceTarget): boolean {
// Check modifier key here and cancel early, it's also checked in resolve as the function
// is used externally.
let shouldPreventDefault = false;
......@@ -135,7 +135,7 @@ export abstract class AbstractKeybindingService implements IKeybindingService {
shouldPreventDefault = true;
this._currentChord = resolveResult.enterChord;
if (this._statusService) {
let firstPartLabel = this.getLabelFor(new Keybinding(this._currentChord));
let firstPartLabel = this.getLabelFor(this._currentChord);
this._currentChordStatusMessage = this._statusService.setStatusMessage(nls.localize('first.chord', "({0}) was pressed. Waiting for second key of chord...", firstPartLabel));
}
return shouldPreventDefault;
......@@ -143,7 +143,7 @@ export abstract class AbstractKeybindingService implements IKeybindingService {
if (this._statusService && this._currentChord) {
if (!resolveResult || !resolveResult.commandId) {
let firstPartLabel = this.getLabelFor(new Keybinding(this._currentChord));
let firstPartLabel = this.getLabelFor(this._currentChord);
let chordPartLabel = this.getLabelFor(keybinding);
this._statusService.setStatusMessage(nls.localize('missing.chord', "The key combination ({0}, {1}) is not a command.", firstPartLabel, chordPartLabel), 10 * 1000 /* 10s */);
shouldPreventDefault = true;
......@@ -153,7 +153,7 @@ export abstract class AbstractKeybindingService implements IKeybindingService {
this._currentChordStatusMessage.dispose();
this._currentChordStatusMessage = null;
}
this._currentChord = 0;
this._currentChord = null;
if (resolveResult && resolveResult.commandId) {
if (!/^\^/.test(resolveResult.commandId)) {
......
......@@ -5,7 +5,7 @@
'use strict';
import { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { Keybinding } from 'vs/base/common/keyCodes';
import { SimpleKeybinding, Keybinding } from 'vs/base/common/keyCodes';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ContextKeyExpr, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
......@@ -69,6 +69,6 @@ export interface IKeybindingService {
getDefaultKeybindings(): string;
lookupKeybindings(commandId: string): Keybinding[];
customKeybindingsCount(): number;
resolve(keybinding: Keybinding, target: IContextKeyServiceTarget): IResolveResult;
resolve(keybinding: SimpleKeybinding, target: IContextKeyServiceTarget): IResolveResult;
}
......@@ -4,14 +4,14 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Keybinding, BinaryKeybindings } from 'vs/base/common/keyCodes';
import { createKeybinding, SimpleKeybinding, Keybinding } from 'vs/base/common/keyCodes';
import { ISimplifiedPlatform, KeybindingLabels } from 'vs/base/common/keybinding';
import * as platform from 'vs/base/common/platform';
import { IKeybindingItem, IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
export interface IResolveResult {
enterChord: number;
enterChord: SimpleKeybinding;
commandId: string;
commandArgs: any;
}
......@@ -30,32 +30,38 @@ interface IChordsMap {
interface ICommandEntry {
when: ContextKeyExpr;
keybinding: number;
keybinding: Keybinding;
commandId: string;
commandArgs: any;
}
export class NormalizedKeybindingItem {
keybinding: number;
command: string;
commandArgs: any;
when: ContextKeyExpr;
isDefault: boolean;
actualCommand: string;
_normalizedKeybindingItemBrand: void;
public readonly keybinding: Keybinding;
public readonly command: string;
public readonly actualCommand: string;
public readonly commandArgs: any;
public readonly when: ContextKeyExpr;
public readonly isDefault: boolean;
public static fromKeybindingItem(source: IKeybindingItem, isDefault: boolean): NormalizedKeybindingItem {
let when: ContextKeyExpr = null;
if (source.when) {
when = source.when.normalize();
}
return new NormalizedKeybindingItem(source.keybinding, source.command, source.commandArgs, when, isDefault);
let keybinding: Keybinding = null;
if (source.keybinding !== 0) {
keybinding = createKeybinding(source.keybinding);
}
return new NormalizedKeybindingItem(keybinding, source.command, source.commandArgs, when, isDefault);
}
constructor(keybinding: number, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean) {
constructor(keybinding: Keybinding, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean) {
this.keybinding = keybinding;
this.command = command;
this.commandArgs = commandArgs;
this.actualCommand = this.command ? this.command.replace(/^\^/, '') : this.command;
this.commandArgs = commandArgs;
this.when = when;
this.isDefault = isDefault;
}
......@@ -92,7 +98,7 @@ export class KeybindingResolver {
let allKeybindings = KeybindingResolver.combine(defaultKeybindings, overrides);
for (let i = 0, len = allKeybindings.length; i < len; i++) {
let k = allKeybindings[i];
if (k.keybinding === 0) {
if (k.keybinding === null) {
continue;
}
......@@ -103,10 +109,10 @@ export class KeybindingResolver {
commandArgs: k.commandArgs
};
if (BinaryKeybindings.hasChord(k.keybinding)) {
if (k.keybinding.isChord()) {
// This is a chord
let keybindingFirstPart = BinaryKeybindings.extractFirstPart(k.keybinding);
let keybindingChordPart = BinaryKeybindings.extractChordPart(k.keybinding);
let keybindingFirstPart = k.keybinding.extractFirstPart().value;
let keybindingChordPart = k.keybinding.extractChordPart().value;
this._chords[keybindingFirstPart] = this._chords[keybindingFirstPart] || Object.create(null);
this._chords[keybindingFirstPart][keybindingChordPart] = this._chords[keybindingFirstPart][keybindingChordPart] || [];
......@@ -115,18 +121,18 @@ export class KeybindingResolver {
this._addKeyPress(keybindingFirstPart, entry, k);
} else {
this._addKeyPress(k.keybinding, entry, k);
this._addKeyPress(k.keybinding.value, entry, k);
}
}
}
private static _isTargetedForRemoval(defaultKb: NormalizedKeybindingItem, keybinding: number, command: string, when: ContextKeyExpr): boolean {
private static _isTargetedForRemoval(defaultKb: NormalizedKeybindingItem, keybinding: Keybinding, command: string, when: ContextKeyExpr): boolean {
if (defaultKb.actualCommand !== command) {
return false;
}
if (keybinding) {
if (defaultKb.keybinding !== keybinding) {
if (!keybinding.equals(defaultKb.keybinding)) {
return false;
}
}
......@@ -182,7 +188,7 @@ export class KeybindingResolver {
continue;
}
if (BinaryKeybindings.hasChord(conflict.keybinding) && BinaryKeybindings.hasChord(entry.keybinding) && conflict.keybinding !== entry.keybinding) {
if (conflict.keybinding.isChord() && entry.keybinding.isChord() && conflict.keybinding.value !== entry.keybinding.value) {
// The conflict only shares the chord start with this command
continue;
}
......@@ -192,7 +198,7 @@ export class KeybindingResolver {
if (this._shouldWarnOnConflict && item.isDefault) {
console.warn('Conflict detected, command `' + conflict.commandId + '` cannot be triggered by ' + KeybindingLabels.toUserSettingsLabel(keypress) + ' due to ' + item.command);
}
KeybindingResolver._push(this._lookupMapUnreachable, conflict.commandId, conflict.keybinding);
KeybindingResolver._push(this._lookupMapUnreachable, conflict.commandId, conflict.keybinding.value);
}
}
......@@ -267,7 +273,7 @@ export class KeybindingResolver {
if (!item.command) {
return;
}
KeybindingResolver._push(this._lookupMap, item.command, item.keybinding);
KeybindingResolver._push(this._lookupMap, item.command, item.keybinding.value);
}
public getDefaultBoundCommands(): IBoundCommands {
......@@ -314,22 +320,22 @@ export class KeybindingResolver {
});
return result.map((trigger) => {
return new Keybinding(trigger);
return createKeybinding(trigger);
}).reverse(); // sort most specific to the top
}
public resolve(context: any, currentChord: number, keypress: number): IResolveResult {
public resolve(context: any, currentChord: SimpleKeybinding, keypress: SimpleKeybinding): IResolveResult {
// console.log('resolve: ' + Keybinding.toUserSettingsLabel(keypress));
let lookupMap: ICommandEntry[] = null;
if (currentChord !== 0) {
let chords = this._chords[currentChord];
if (currentChord !== null) {
let chords = this._chords[currentChord.value];
if (!chords) {
return null;
}
lookupMap = chords[keypress];
lookupMap = chords[keypress.value];
} else {
lookupMap = this._map[keypress];
lookupMap = this._map[keypress.value];
}
......@@ -338,7 +344,7 @@ export class KeybindingResolver {
return null;
}
if (currentChord === 0 && BinaryKeybindings.hasChord(result.keybinding)) {
if (currentChord === null && result.keybinding.isChord()) {
return {
enterChord: keypress,
commandId: null,
......@@ -347,7 +353,7 @@ export class KeybindingResolver {
}
return {
enterChord: 0,
enterChord: null,
commandId: result.commandId,
commandArgs: result.commandArgs
};
......
......@@ -5,7 +5,7 @@
'use strict';
import * as assert from 'assert';
import { Keybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { SimpleKeybinding, createKeybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { KeybindingLabels } from 'vs/base/common/keybinding';
import { IDisposable } from 'vs/base/common/lifecycle';
......@@ -38,7 +38,7 @@ suite('AbstractKeybindingService', () => {
return this._resolver;
}
public dispatch(keybinding: Keybinding): boolean {
public dispatch(keybinding: SimpleKeybinding): boolean {
return this._dispatch(keybinding, null);
}
}
......@@ -143,12 +143,12 @@ suite('AbstractKeybindingService', () => {
]);
// send Ctrl/Cmd + K
let shouldPreventDefault = kbService.dispatch(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
let shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
assert.equal(shouldPreventDefault, true);
assert.deepEqual(executeCommandCalls, []);
assert.deepEqual(showMessageCalls, []);
assert.deepEqual(statusMessageCalls, [
`(${KeybindingLabels._toUSLabel(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}) was pressed. Waiting for second key of chord...`
`(${KeybindingLabels._toUSLabel(createKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}) was pressed. Waiting for second key of chord...`
]);
assert.deepEqual(statusMessageCallsDisposed, []);
executeCommandCalls = [];
......@@ -157,15 +157,15 @@ suite('AbstractKeybindingService', () => {
statusMessageCallsDisposed = [];
// send backspace
shouldPreventDefault = kbService.dispatch(new Keybinding(KeyCode.Backspace));
shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyCode.Backspace));
assert.equal(shouldPreventDefault, true);
assert.deepEqual(executeCommandCalls, []);
assert.deepEqual(showMessageCalls, []);
assert.deepEqual(statusMessageCalls, [
`The key combination (${KeybindingLabels._toUSLabel(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}, ${KeybindingLabels._toUSLabel(new Keybinding(KeyCode.Backspace))}) is not a command.`
`The key combination (${KeybindingLabels._toUSLabel(createKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}, ${KeybindingLabels._toUSLabel(createKeybinding(KeyCode.Backspace))}) is not a command.`
]);
assert.deepEqual(statusMessageCallsDisposed, [
`(${KeybindingLabels._toUSLabel(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}) was pressed. Waiting for second key of chord...`
`(${KeybindingLabels._toUSLabel(createKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}) was pressed. Waiting for second key of chord...`
]);
executeCommandCalls = [];
showMessageCalls = [];
......@@ -173,7 +173,7 @@ suite('AbstractKeybindingService', () => {
statusMessageCallsDisposed = [];
// send backspace
shouldPreventDefault = kbService.dispatch(new Keybinding(KeyCode.Backspace));
shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyCode.Backspace));
assert.equal(shouldPreventDefault, true);
assert.deepEqual(executeCommandCalls, [{
commandId: 'simpleCommand',
......@@ -205,7 +205,7 @@ suite('AbstractKeybindingService', () => {
]);
function assertIsIgnored(keybinding: number): void {
let shouldPreventDefault = kbService.dispatch(new Keybinding(keybinding));
let shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(keybinding));
assert.equal(shouldPreventDefault, false);
assert.deepEqual(executeCommandCalls, []);
assert.deepEqual(showMessageCalls, []);
......@@ -242,7 +242,7 @@ suite('AbstractKeybindingService', () => {
currentContextValue = {
key1: true
};
let shouldPreventDefault = kbService.dispatch(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
let shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
assert.equal(shouldPreventDefault, true);
assert.deepEqual(executeCommandCalls, [{
commandId: 'simpleCommand',
......@@ -258,12 +258,12 @@ suite('AbstractKeybindingService', () => {
// send Ctrl/Cmd + K
currentContextValue = {};
shouldPreventDefault = kbService.dispatch(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
assert.equal(shouldPreventDefault, true);
assert.deepEqual(executeCommandCalls, []);
assert.deepEqual(showMessageCalls, []);
assert.deepEqual(statusMessageCalls, [
`(${KeybindingLabels._toUSLabel(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}) was pressed. Waiting for second key of chord...`
`(${KeybindingLabels._toUSLabel(createKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}) was pressed. Waiting for second key of chord...`
]);
assert.deepEqual(statusMessageCallsDisposed, []);
executeCommandCalls = [];
......@@ -273,7 +273,7 @@ suite('AbstractKeybindingService', () => {
// send Ctrl/Cmd + X
currentContextValue = {};
shouldPreventDefault = kbService.dispatch(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_X));
shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_X));
assert.equal(shouldPreventDefault, true);
assert.deepEqual(executeCommandCalls, [{
commandId: 'chordCommand',
......@@ -282,7 +282,7 @@ suite('AbstractKeybindingService', () => {
assert.deepEqual(showMessageCalls, []);
assert.deepEqual(statusMessageCalls, []);
assert.deepEqual(statusMessageCallsDisposed, [
`(${KeybindingLabels._toUSLabel(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}) was pressed. Waiting for second key of chord...`
`(${KeybindingLabels._toUSLabel(createKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K))}) was pressed. Waiting for second key of chord...`
]);
executeCommandCalls = [];
showMessageCalls = [];
......@@ -302,7 +302,7 @@ suite('AbstractKeybindingService', () => {
// send Ctrl/Cmd + K
currentContextValue = {};
let shouldPreventDefault = kbService.dispatch(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
let shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
assert.equal(shouldPreventDefault, true);
assert.deepEqual(executeCommandCalls, [{
commandId: 'simpleCommand',
......@@ -320,7 +320,7 @@ suite('AbstractKeybindingService', () => {
currentContextValue = {
key1: true
};
shouldPreventDefault = kbService.dispatch(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
assert.equal(shouldPreventDefault, true);
assert.deepEqual(executeCommandCalls, [{
commandId: 'simpleCommand',
......@@ -338,7 +338,7 @@ suite('AbstractKeybindingService', () => {
currentContextValue = {
key1: true
};
shouldPreventDefault = kbService.dispatch(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_X));
shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_X));
assert.equal(shouldPreventDefault, false);
assert.deepEqual(executeCommandCalls, []);
assert.deepEqual(showMessageCalls, []);
......@@ -360,7 +360,7 @@ suite('AbstractKeybindingService', () => {
// send Ctrl/Cmd + K
currentContextValue = {};
let shouldPreventDefault = kbService.dispatch(new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
let shouldPreventDefault = kbService.dispatch(new SimpleKeybinding(KeyMod.CtrlCmd | KeyCode.KEY_K));
assert.equal(shouldPreventDefault, false);
assert.deepEqual(executeCommandCalls, [{
commandId: 'simpleCommand',
......
......@@ -134,7 +134,7 @@ suite('Keybinding IO', () => {
let userKeybinding = <IUserFriendlyKeybinding>JSON.parse(strJSON)[0];
let keybindingItem = IOSupport.readKeybindingItem(userKeybinding, 0);
let normalizedKeybindingItem = NormalizedKeybindingItem.fromKeybindingItem(keybindingItem, false);
assert.equal(normalizedKeybindingItem.keybinding, 0);
assert.equal(normalizedKeybindingItem.keybinding, null);
});
test('test commands args', () => {
......
......@@ -5,7 +5,7 @@
'use strict';
import * as assert from 'assert';
import { BinaryKeybindings, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { createKeybinding, SimpleKeybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { IOSupport, KeybindingResolver, NormalizedKeybindingItem } from 'vs/platform/keybinding/common/keybindingResolver';
import { IKeybindingItem } from 'vs/platform/keybinding/common/keybinding';
import { ContextKeyAndExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
......@@ -27,8 +27,8 @@ suite('Keybinding Service', () => {
assert.equal(KeybindingResolver.contextMatchesRules({ bar: 'bz' }, contextRules), false);
let resolver = new KeybindingResolver([keybindingItem], []);
assert.equal(resolver.resolve({ bar: 'baz' }, 0, keybinding).commandId, 'yes');
assert.equal(resolver.resolve({ bar: 'bz' }, 0, keybinding), null);
assert.equal(resolver.resolve({ bar: 'baz' }, null, new SimpleKeybinding(keybinding)).commandId, 'yes');
assert.equal(resolver.resolve({ bar: 'bz' }, null, new SimpleKeybinding(keybinding)), null);
});
test('resolve key with arguments', function () {
......@@ -45,7 +45,7 @@ suite('Keybinding Service', () => {
};
let resolver = new KeybindingResolver([keybindingItem], []);
assert.equal(resolver.resolve({ bar: 'baz' }, 0, keybinding).commandArgs, commandArgs);
assert.equal(resolver.resolve({ bar: 'baz' }, null, new SimpleKeybinding(keybinding)).commandArgs, commandArgs);
});
test('KbAndExpression.equals', function () {
......@@ -91,8 +91,8 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_A, 'yes1', null, ContextKeyExpr.equals('1', 'a'), true),
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), false),
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_A), 'yes1', null, ContextKeyExpr.equals('1', 'a'), true),
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), false),
]);
});
......@@ -119,9 +119,9 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_A, 'yes1', null, ContextKeyExpr.equals('1', 'a'), true),
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true),
new NormalizedKeybindingItem(KeyCode.KEY_C, 'yes3', null, ContextKeyExpr.equals('3', 'c'), false),
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_A), 'yes1', null, ContextKeyExpr.equals('1', 'a'), true),
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true),
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_C), 'yes3', null, ContextKeyExpr.equals('3', 'c'), false),
]);
});
......@@ -148,8 +148,8 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_A, 'yes1', null, ContextKeyExpr.equals('1', 'a'), true),
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_A), 'yes1', null, ContextKeyExpr.equals('1', 'a'), true),
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
]);
});
......@@ -176,8 +176,8 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_A, 'yes1', null, ContextKeyExpr.equals('1', 'a'), true),
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_A), 'yes1', null, ContextKeyExpr.equals('1', 'a'), true),
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
]);
});
......@@ -204,7 +204,7 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
]);
});
......@@ -231,7 +231,7 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
]);
});
......@@ -258,7 +258,7 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
]);
});
......@@ -285,7 +285,7 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
]);
});
......@@ -312,7 +312,7 @@ suite('Keybinding Service', () => {
}];
let actual = KeybindingResolver.combine(defaults, overrides);
assert.deepEqual(actual, [
new NormalizedKeybindingItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true)
]);
});
......@@ -497,13 +497,14 @@ suite('Keybinding Service', () => {
}
};
let testResolve = (ctx: any, expectedKey: number, commandId: string) => {
let testResolve = (ctx: any, _expectedKey: number, commandId: string) => {
let expectedKey = createKeybinding(_expectedKey);
if (BinaryKeybindings.hasChord(expectedKey)) {
let firstPart = BinaryKeybindings.extractFirstPart(expectedKey);
let chordPart = BinaryKeybindings.extractChordPart(expectedKey);
if (expectedKey.isChord()) {
let firstPart = expectedKey.extractFirstPart();
let chordPart = expectedKey.extractChordPart();
let result = resolver.resolve(ctx, 0, firstPart);
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, firstPart, 'Enters chord for ' + commandId);
......@@ -511,12 +512,12 @@ suite('Keybinding Service', () => {
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, 0, 'Finds chorded command ' + commandId);
assert.equal(result.enterChord, null, 'Finds chorded command ' + commandId);
} else {
let result = resolver.resolve(ctx, 0, expectedKey);
let result = resolver.resolve(ctx, null, expectedKey);
assert.ok(result !== null, 'Finds command ' + commandId);
assert.equal(result.commandId, commandId, 'Finds command ' + commandId);
assert.equal(result.enterChord, 0, 'Finds command ' + commandId);
assert.equal(result.enterChord, null, 'Finds command ' + commandId);
}
};
......
......@@ -198,7 +198,7 @@ export abstract class EditorGroupPicker extends BaseEditorPicker {
return super.getAutoFocus(searchValue);
}
const isShiftNavigate = (quickNavigateConfiguration && quickNavigateConfiguration.keybindings.some(k => k.hasShift()));
const isShiftNavigate = (quickNavigateConfiguration && quickNavigateConfiguration.keybindings.some(k => !k.isChord() && k.hasShift()));
if (isShiftNavigate) {
return {
autoFocusLastEntry: true
......
......@@ -36,7 +36,7 @@ import { EditorOptions } from 'vs/workbench/common/editor';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { CombinedInstallAction, UpdateAction, EnableAction, DisableAction, BuiltinStatusLabelAction, ReloadAction } from 'vs/workbench/parts/extensions/browser/extensionsActions';
import WebView from 'vs/workbench/parts/html/browser/webview';
import { Keybinding } from 'vs/base/common/keyCodes';
import { createKeybinding } from 'vs/base/common/keyCodes';
import { KeybindingLabels } from 'vs/base/common/keybinding';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
......@@ -669,7 +669,7 @@ export class ExtensionEditor extends BaseEditor {
case 'darwin': key = rawKeyBinding.mac; break;
}
const keyBinding = new Keybinding(KeybindingLabels.fromUserSettingsLabel(key || rawKeyBinding.key));
const keyBinding = createKeybinding(KeybindingLabels.fromUserSettingsLabel(key || rawKeyBinding.key));
const result = this.keybindingService.getLabelFor(keyBinding);
return result === 'unknown' ? null : result;
}
......
......@@ -22,7 +22,7 @@ import { CollapseAllAction as TreeCollapseAction } from 'vs/base/parts/tree/brow
import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Keybinding, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { createKeybinding, Keybinding, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { toResource } from 'vs/workbench/common/editor';
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -37,11 +37,14 @@ export function isSearchViewletFocussed(viewletService: IViewletService): boolea
return activeViewlet && activeViewlet.getId() === Constants.VIEWLET_ID && activeElement && DOM.isAncestor(activeElement, (<SearchViewlet>activeViewlet).getContainer().getHTMLElement());
}
export function appendKeyBindingLabel(label: string, keyBinding: Keybinding, keyBindingService2: IKeybindingService): string;
export function appendKeyBindingLabel(label: string, keyBinding: number, keyBindingService2: IKeybindingService): string;
export function appendKeyBindingLabel(label: string, keyBinding: any, keyBindingService2: IKeybindingService): string {
keyBinding = typeof keyBinding === 'number' ? new Keybinding(keyBinding) : keyBinding;
return keyBinding ? label + ' (' + keyBindingService2.getLabelFor(keyBinding) + ')' : label;
export function appendKeyBindingLabel(label: string, keyBinding: number | Keybinding, keyBindingService2: IKeybindingService): string {
let kb: Keybinding;
if (typeof keyBinding === 'number') {
kb = createKeybinding(keyBinding);
} else {
kb = keyBinding;
}
return kb ? label + ' (' + keyBindingService2.getLabelFor(kb) + ')' : label;
}
export class ToggleCaseSensitiveAction extends Action {
......
......@@ -19,7 +19,7 @@ import { ReleaseNotesInput } from 'vs/workbench/parts/update/electron-browser/re
import { IRequestService } from 'vs/platform/request/node/request';
import { asText } from 'vs/base/node/request';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { Keybinding } from 'vs/base/common/keyCodes';
import { createKeybinding } from 'vs/base/common/keyCodes';
import { KeybindingLabels } from 'vs/base/common/keybinding';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
......@@ -79,7 +79,7 @@ export function loadReleaseNotes(accessor: ServicesAccessor, version: string): T
return unassigned;
}
const keybinding = new Keybinding(code);
const keybinding = createKeybinding(code);
if (!keybinding) {
return unassigned;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册