diff --git a/src/vs/platform/keybinding/common/abstractKeybindingService.ts b/src/vs/platform/keybinding/common/abstractKeybindingService.ts index b678ab9fe36e8a889f16686f488539aa4291f652..722dd085ce7f9781f8a1b558f8de62fe8a3b99c2 100644 --- a/src/vs/platform/keybinding/common/abstractKeybindingService.ts +++ b/src/vs/platform/keybinding/common/abstractKeybindingService.ts @@ -23,7 +23,7 @@ import { NormalizedKeybindingItem } from 'vs/platform/keybinding/common/normaliz import { OS, OperatingSystem } from 'vs/base/common/platform'; /** - * Do not instantiate. Use KeybindingService to get a ResolvedKeybinding. + * Do not instantiate. Use KeybindingService to get a ResolvedKeybinding seeded with information about the current kb layout. */ export class USLayoutResolvedKeybinding extends ResolvedKeybinding { @@ -57,17 +57,17 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding { } public getLabel(): string { - const [firstPart, chordPart] = PrintableKeypress.fromKeybinding2(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUILabel, this._os); + const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUILabel, this._os); return UILabelProvider.toLabel2(firstPart, chordPart, this._os); } public getAriaLabel(): string { - const [firstPart, chordPart] = PrintableKeypress.fromKeybinding2(this._actual, USLayoutResolvedKeybinding._usKeyCodeToAriaLabel, this._os); + const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToAriaLabel, this._os); return AriaLabelProvider.toLabel2(firstPart, chordPart, this._os); } public getHTMLLabel(): IHTMLContentElement[] { - const [firstPart, chordPart] = PrintableKeypress.fromKeybinding2(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUILabel, this._os); + const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUILabel, this._os); return UILabelProvider.toHTMLLabel2(firstPart, chordPart, this._os); } @@ -98,7 +98,7 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding { return null; } - const [firstPart, chordPart] = PrintableKeypress.fromKeybinding2(this._actual, USLayoutResolvedKeybinding._usKeyCodeToElectronAccelerator, this._os); + const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToElectronAccelerator, this._os); return ElectronAcceleratorLabelProvider.toLabel2(firstPart, chordPart, this._os); } diff --git a/src/vs/platform/keybinding/common/keybindingIO.ts b/src/vs/platform/keybinding/common/keybindingIO.ts index a70ecdf2c1ac7a865decb7d90cb8c11f2e757577..e944b6487416831fbb654907c122bebc3d01bf0c 100644 --- a/src/vs/platform/keybinding/common/keybindingIO.ts +++ b/src/vs/platform/keybinding/common/keybindingIO.ts @@ -86,7 +86,7 @@ export class KeybindingIO { } public static writeKeybinding(keybinding: Keybinding, OS: OperatingSystem): string { - const [firstPart, chordPart] = PrintableKeypress.fromKeybinding2(keybinding, this._keyCodeToStr, OS); + const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(keybinding, this._keyCodeToStr, OS); let result = UserSettingsLabelProvider.toLabel2(firstPart, chordPart, OS); return result.toLowerCase(); diff --git a/src/vs/platform/keybinding/common/keybindingLabels.ts b/src/vs/platform/keybinding/common/keybindingLabels.ts index f1164c42de3efb4187d1f41c03a4ad7778c91bb3..69899d6ca380866b318310e3ef04950ef7b2aea0 100644 --- a/src/vs/platform/keybinding/common/keybindingLabels.ts +++ b/src/vs/platform/keybinding/common/keybindingLabels.ts @@ -10,13 +10,13 @@ import { OperatingSystem } from 'vs/base/common/platform'; import { IHTMLContentElement } from 'vs/base/common/htmlContent'; import { Keybinding, SimpleKeybinding, KeyCode } from 'vs/base/common/keyCodes'; -export interface IKeyCodeLabelProvider2 { +export interface IKeyCodeLabelProvider { (keyCode: KeyCode, OS: OperatingSystem): string; } export class PrintableKeypress { - public static fromSimpleKeybinding2(keybinding: SimpleKeybinding, labelProvider: IKeyCodeLabelProvider2, OS: OperatingSystem): PrintableKeypress { + public static fromSimpleKeybinding(keybinding: SimpleKeybinding, labelProvider: IKeyCodeLabelProvider, OS: OperatingSystem): PrintableKeypress { const ctrlCmd = keybinding.hasCtrlCmd(); const winCtrl = keybinding.hasWinCtrl(); @@ -31,13 +31,13 @@ export class PrintableKeypress { return new PrintableKeypress(ctrlKey, shiftKey, altKey, metaKey, keyLabel); } - public static fromKeybinding2(keybinding: Keybinding, labelProvider: IKeyCodeLabelProvider2, OS: OperatingSystem): [PrintableKeypress, PrintableKeypress] { + public static fromKeybinding(keybinding: Keybinding, labelProvider: IKeyCodeLabelProvider, OS: OperatingSystem): [PrintableKeypress, PrintableKeypress] { if (keybinding.isChord()) { - const firstPart = PrintableKeypress.fromSimpleKeybinding2(keybinding.extractFirstPart(), labelProvider, OS); - const chordPart = PrintableKeypress.fromSimpleKeybinding2(keybinding.extractChordPart(), labelProvider, OS); + const firstPart = PrintableKeypress.fromSimpleKeybinding(keybinding.extractFirstPart(), labelProvider, OS); + const chordPart = PrintableKeypress.fromSimpleKeybinding(keybinding.extractChordPart(), labelProvider, OS); return [firstPart, chordPart]; } else { - const printableKeypress = PrintableKeypress.fromSimpleKeybinding2(keybinding, labelProvider, OS); + const printableKeypress = PrintableKeypress.fromSimpleKeybinding(keybinding, labelProvider, OS); return [printableKeypress, null]; } } diff --git a/src/vs/platform/keybinding/common/normalizedKeybindingItem.ts b/src/vs/platform/keybinding/common/normalizedKeybindingItem.ts index acc828458814ca0946e1ac98678ac5f7c83a6f64..e97bcf1830a2f2e88186c4047399e628b9120803 100644 --- a/src/vs/platform/keybinding/common/normalizedKeybindingItem.ts +++ b/src/vs/platform/keybinding/common/normalizedKeybindingItem.ts @@ -30,23 +30,26 @@ export class NormalizedKeybindingItem { if (source.keybinding !== 0) { keybinding = createKeybinding(source.keybinding); } - return new NormalizedKeybindingItem(keybinding, source.command, source.commandArgs, when, isDefault); - } - - constructor(keybinding: Keybinding, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean) { - this.keybinding = keybinding; + let keypressFirstPart: string; + let keypressChordPart: string; if (keybinding === null) { - this.keypressFirstPart = null; - this.keypressChordPart = null; + keypressFirstPart = null; + keypressChordPart = null; } else if (keybinding.isChord()) { - this.keypressFirstPart = keybinding.extractFirstPart().value.toString(); - this.keypressChordPart = keybinding.extractChordPart().value.toString(); + keypressFirstPart = keybinding.extractFirstPart().value.toString(); + keypressChordPart = keybinding.extractChordPart().value.toString(); } else { - this.keypressFirstPart = keybinding.value.toString(); - this.keypressChordPart = null; + keypressFirstPart = keybinding.value.toString(); + keypressChordPart = null; } + return new NormalizedKeybindingItem(keybinding, keypressFirstPart, keypressChordPart, source.command, source.commandArgs, when, isDefault); + } + constructor(keybinding: Keybinding, keypressFirstPart: string, keypressChordPart: string, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean) { + this.keybinding = keybinding; + this.keypressFirstPart = keypressFirstPart; + this.keypressChordPart = keypressChordPart; this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false); this.command = this.bubble ? command.substr(1) : command; this.commandArgs = commandArgs; diff --git a/src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts b/src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts index 2af594b030acd70cad4c5d7b83d91afafcaf71c4..43ce87875bbddbaaa48c334aca674006afd768b8 100644 --- a/src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts +++ b/src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts @@ -129,8 +129,14 @@ suite('AbstractKeybindingService', () => { }); function kbItem(keybinding: number, command: string, when: ContextKeyExpr = null): NormalizedKeybindingItem { - let kb = (keybinding !== 0 ? createKeybinding(keybinding) : null); - return new NormalizedKeybindingItem(kb, command, null, when, true); + return NormalizedKeybindingItem.fromKeybindingItem({ + keybinding: keybinding, + command: command, + commandArgs: null, + when: when, + weight1: 0, + weight2: 0 + }, true); } function toUsLabel(keybinding: number): string { diff --git a/src/vs/platform/keybinding/test/common/keybindingResolver.test.ts b/src/vs/platform/keybinding/test/common/keybindingResolver.test.ts index b2e1c0a498428f6f20c3c1383462409b6862e2dd..5e9da9e5b7e260e63fc426fcfd8f27367322b41e 100644 --- a/src/vs/platform/keybinding/test/common/keybindingResolver.test.ts +++ b/src/vs/platform/keybinding/test/common/keybindingResolver.test.ts @@ -13,8 +13,14 @@ import { NormalizedKeybindingItem } from 'vs/platform/keybinding/common/normaliz suite('KeybindingResolver', () => { function kbItem(keybinding: number, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean): NormalizedKeybindingItem { - let kb = (keybinding !== 0 ? createKeybinding(keybinding) : null); - return new NormalizedKeybindingItem(kb, command, commandArgs, when, isDefault); + return NormalizedKeybindingItem.fromKeybindingItem({ + keybinding: keybinding, + command: command, + commandArgs: commandArgs, + when: when, + weight1: 0, + weight2: 0 + }, isDefault); } test('resolve key', function () { @@ -49,8 +55,8 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - 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), + kbItem(KeyCode.KEY_A, 'yes1', null, ContextKeyExpr.equals('1', 'a'), true), + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), false), ]); }); @@ -64,9 +70,9 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - 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), + kbItem(KeyCode.KEY_A, 'yes1', null, ContextKeyExpr.equals('1', 'a'), true), + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true), + kbItem(KeyCode.KEY_C, 'yes3', null, ContextKeyExpr.equals('3', 'c'), false), ]); }); @@ -80,8 +86,8 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - 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) + kbItem(KeyCode.KEY_A, 'yes1', null, ContextKeyExpr.equals('1', 'a'), true), + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) ]); }); @@ -95,8 +101,8 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - 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) + kbItem(KeyCode.KEY_A, 'yes1', null, ContextKeyExpr.equals('1', 'a'), true), + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) ]); }); @@ -110,7 +116,7 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) ]); }); @@ -124,7 +130,7 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) ]); }); @@ -138,7 +144,7 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) ]); }); @@ -152,7 +158,7 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) ]); }); @@ -166,7 +172,7 @@ suite('KeybindingResolver', () => { ]; let actual = KeybindingResolver.combine(defaults, overrides); assert.deepEqual(actual, [ - new NormalizedKeybindingItem(createKeybinding(KeyCode.KEY_B), 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) + kbItem(KeyCode.KEY_B, 'yes2', null, ContextKeyExpr.equals('2', 'b'), true) ]); }); diff --git a/src/vs/workbench/services/keybinding/electron-browser/keybindingService.ts b/src/vs/workbench/services/keybinding/electron-browser/keybindingService.ts index 83d770da0beec23204c0e1bd5bc7fc950b8fc2e0..a0a28312ecdf3dda81cfb940f3f2210ef0b11424 100644 --- a/src/vs/workbench/services/keybinding/electron-browser/keybindingService.ts +++ b/src/vs/workbench/services/keybinding/electron-browser/keybindingService.ts @@ -130,21 +130,21 @@ export class FancyResolvedKeybinding extends ResolvedKeybinding { public getLabel(): string { const keyCodeLabelProvider = getNativeUIKeyCodeLabelProvider(); - const [firstPart, chordPart] = PrintableKeypress.fromKeybinding2(this._actual, keyCodeLabelProvider, OS); + const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, keyCodeLabelProvider, OS); return UILabelProvider.toLabel2(firstPart, chordPart, OS); } public getAriaLabel(): string { const keyCodeLabelProvider = getNativeAriaKeyCodeLabelProvider(); - const [firstPart, chordPart] = PrintableKeypress.fromKeybinding2(this._actual, keyCodeLabelProvider, OS); + const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, keyCodeLabelProvider, OS); return AriaLabelProvider.toLabel2(firstPart, chordPart, OS); } public getHTMLLabel(): IHTMLContentElement[] { const keyCodeLabelProvider = getNativeUIKeyCodeLabelProvider(); - const [firstPart, chordPart] = PrintableKeypress.fromKeybinding2(this._actual, keyCodeLabelProvider, OS); + const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, keyCodeLabelProvider, OS); return UILabelProvider.toHTMLLabel2(firstPart, chordPart, OS); } diff --git a/src/vs/workbench/services/keybinding/electron-browser/nativeKeymap.ts b/src/vs/workbench/services/keybinding/electron-browser/nativeKeymap.ts index ef6c295ef5c8741ff95357d368c62f20591319a3..da40ef09ddb49463cb00cf5a89118a4bfca17790 100644 --- a/src/vs/workbench/services/keybinding/electron-browser/nativeKeymap.ts +++ b/src/vs/workbench/services/keybinding/electron-browser/nativeKeymap.ts @@ -7,7 +7,7 @@ import * as nativeKeymap from 'native-keymap'; import { KeyCode, KeyCodeUtils } from 'vs/base/common/keyCodes'; import { CharCode } from 'vs/base/common/charCode'; -import { IKeyCodeLabelProvider2 } from 'vs/platform/keybinding/common/keybindingLabels'; +import { IKeyCodeLabelProvider } from 'vs/platform/keybinding/common/keybindingLabels'; import { lookupKeyCode, setExtractKeyCode } from 'vs/base/browser/keyboardEvent'; import Platform = require('vs/base/common/platform'); @@ -332,8 +332,8 @@ setExtractKeyCode((e: KeyboardEvent) => { return lookupKeyCode(e); }); -let nativeUIKeyCodeLabelProvider: IKeyCodeLabelProvider2 = null; -export function getNativeUIKeyCodeLabelProvider(): IKeyCodeLabelProvider2 { +let nativeUIKeyCodeLabelProvider: IKeyCodeLabelProvider = null; +export function getNativeUIKeyCodeLabelProvider(): IKeyCodeLabelProvider { if (!nativeUIKeyCodeLabelProvider) { let remaps = getNativeLabelProviderRemaps(); nativeUIKeyCodeLabelProvider = (keyCode: KeyCode, OS: Platform.OperatingSystem): string => { @@ -360,8 +360,8 @@ export function getNativeUIKeyCodeLabelProvider(): IKeyCodeLabelProvider2 { return nativeUIKeyCodeLabelProvider; } -let nativeAriaKeyCodeLabelProvider: IKeyCodeLabelProvider2 = null; -export function getNativeAriaKeyCodeLabelProvider(): IKeyCodeLabelProvider2 { +let nativeAriaKeyCodeLabelProvider: IKeyCodeLabelProvider = null; +export function getNativeAriaKeyCodeLabelProvider(): IKeyCodeLabelProvider { if (!nativeAriaKeyCodeLabelProvider) { let remaps = getNativeLabelProviderRemaps(); nativeAriaKeyCodeLabelProvider = (keyCode: KeyCode, OS: Platform.OperatingSystem): string => {