diff --git a/src/vs/platform/keybinding/common/keybindingIO.ts b/src/vs/platform/keybinding/common/keybindingIO.ts index f41a3abf0b04e6f750490c31b0e105b5b7e67878..282d8bb69249a11fdab17579d74de5c45ae92d54 100644 --- a/src/vs/platform/keybinding/common/keybindingIO.ts +++ b/src/vs/platform/keybinding/common/keybindingIO.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { Keybinding } from 'vs/base/common/keyCodes'; +import { Keybinding, KeyMod, KeyChord, USER_SETTINGS } from 'vs/base/common/keyCodes'; import { ISimplifiedPlatform, KeybindingLabels } from 'vs/platform/keybinding/common/keybindingLabels'; import * as platform from 'vs/base/common/platform'; import { IKeybindingItem, IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding'; @@ -66,7 +66,87 @@ export class KeybindingIO { } public static readKeybinding(input: string, Platform: ISimplifiedPlatform = platform): number { - return KeybindingLabels.fromUserSettingsLabel(input, Platform); + if (!input) { + return null; + } + input = input.toLowerCase().trim(); + + let ctrlCmd = false, + shift = false, + alt = false, + winCtrl = false, + key: string = ''; + + while (/^(ctrl|shift|alt|meta|win|cmd)(\+|\-)/.test(input)) { + if (/^ctrl(\+|\-)/.test(input)) { + if (Platform.isMacintosh) { + winCtrl = true; + } else { + ctrlCmd = true; + } + input = input.substr('ctrl-'.length); + } + if (/^shift(\+|\-)/.test(input)) { + shift = true; + input = input.substr('shift-'.length); + } + if (/^alt(\+|\-)/.test(input)) { + alt = true; + input = input.substr('alt-'.length); + } + if (/^meta(\+|\-)/.test(input)) { + if (Platform.isMacintosh) { + ctrlCmd = true; + } else { + winCtrl = true; + } + input = input.substr('meta-'.length); + } + if (/^win(\+|\-)/.test(input)) { + if (Platform.isMacintosh) { + ctrlCmd = true; + } else { + winCtrl = true; + } + input = input.substr('win-'.length); + } + if (/^cmd(\+|\-)/.test(input)) { + if (Platform.isMacintosh) { + ctrlCmd = true; + } else { + winCtrl = true; + } + input = input.substr('cmd-'.length); + } + } + + let chord: number = 0; + + let firstSpaceIdx = input.indexOf(' '); + if (firstSpaceIdx > 0) { + key = input.substring(0, firstSpaceIdx); + chord = KeybindingIO.readKeybinding(input.substring(firstSpaceIdx), Platform); + } else { + key = input; + } + + let keyCode = USER_SETTINGS.toKeyCode(key); + + let result = 0; + if (ctrlCmd) { + result |= KeyMod.CtrlCmd; + } + if (shift) { + result |= KeyMod.Shift; + } + if (alt) { + result |= KeyMod.Alt; + } + if (winCtrl) { + result |= KeyMod.WinCtrl; + } + result |= keyCode; + return KeyChord(result, chord); } } diff --git a/src/vs/platform/keybinding/common/keybindingLabels.ts b/src/vs/platform/keybinding/common/keybindingLabels.ts index 2accde99cd3707591753d2c8c993b769139ebc3e..de0465b647cc9ca20dabd8ddb19cb8ff8111d54c 100644 --- a/src/vs/platform/keybinding/common/keybindingLabels.ts +++ b/src/vs/platform/keybinding/common/keybindingLabels.ts @@ -8,7 +8,7 @@ import * as nls from 'vs/nls'; import * as defaultPlatform from 'vs/base/common/platform'; import { IHTMLContentElement } from 'vs/base/common/htmlContent'; -import { Keybinding, SimpleKeybinding, KeyCode, KeyMod, KeyChord, KeyCodeUtils, USER_SETTINGS } from 'vs/base/common/keyCodes'; +import { Keybinding, SimpleKeybinding, KeyCode, KeyCodeUtils, USER_SETTINGS } from 'vs/base/common/keyCodes'; export interface ISimplifiedPlatform { isMacintosh: boolean; @@ -54,93 +54,6 @@ export class KeybindingLabels { return result; } - /** - * @internal - */ - public static fromUserSettingsLabel(input: string, Platform: ISimplifiedPlatform = defaultPlatform): number { - if (!input) { - return null; - } - input = input.toLowerCase().trim(); - - let ctrlCmd = false, - shift = false, - alt = false, - winCtrl = false, - key: string = ''; - - while (/^(ctrl|shift|alt|meta|win|cmd)(\+|\-)/.test(input)) { - if (/^ctrl(\+|\-)/.test(input)) { - if (Platform.isMacintosh) { - winCtrl = true; - } else { - ctrlCmd = true; - } - input = input.substr('ctrl-'.length); - } - if (/^shift(\+|\-)/.test(input)) { - shift = true; - input = input.substr('shift-'.length); - } - if (/^alt(\+|\-)/.test(input)) { - alt = true; - input = input.substr('alt-'.length); - } - if (/^meta(\+|\-)/.test(input)) { - if (Platform.isMacintosh) { - ctrlCmd = true; - } else { - winCtrl = true; - } - input = input.substr('meta-'.length); - } - if (/^win(\+|\-)/.test(input)) { - if (Platform.isMacintosh) { - ctrlCmd = true; - } else { - winCtrl = true; - } - input = input.substr('win-'.length); - } - if (/^cmd(\+|\-)/.test(input)) { - if (Platform.isMacintosh) { - ctrlCmd = true; - } else { - winCtrl = true; - } - input = input.substr('cmd-'.length); - } - } - - let chord: number = 0; - - let firstSpaceIdx = input.indexOf(' '); - if (firstSpaceIdx > 0) { - key = input.substring(0, firstSpaceIdx); - chord = KeybindingLabels.fromUserSettingsLabel(input.substring(firstSpaceIdx), Platform); - } else { - key = input; - } - - let keyCode = USER_SETTINGS.toKeyCode(key); - - let result = 0; - if (ctrlCmd) { - result |= KeyMod.CtrlCmd; - } - if (shift) { - result |= KeyMod.Shift; - } - if (alt) { - result |= KeyMod.Alt; - } - if (winCtrl) { - result |= KeyMod.WinCtrl; - } - result |= keyCode; - return KeyChord(result, chord); - } - /** * Format the binding to a format appropiate for rendering in the UI * @internal diff --git a/src/vs/workbench/parts/extensions/browser/extensionEditor.ts b/src/vs/workbench/parts/extensions/browser/extensionEditor.ts index 5fbda95d6f6de31d0ea34560fee7ae370cc47b78..9534d57443cb3e37de556513cf3c7eec67b217de 100644 --- a/src/vs/workbench/parts/extensions/browser/extensionEditor.ts +++ b/src/vs/workbench/parts/extensions/browser/extensionEditor.ts @@ -37,7 +37,7 @@ 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 { createKeybinding } from 'vs/base/common/keyCodes'; -import { KeybindingLabels } from 'vs/platform/keybinding/common/keybindingLabels'; +import { KeybindingIO } from 'vs/platform/keybinding/common/keybindingIO'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; import { IMessageService } from 'vs/platform/message/common/message'; @@ -669,7 +669,7 @@ export class ExtensionEditor extends BaseEditor { case 'darwin': key = rawKeyBinding.mac; break; } - const keyBinding = createKeybinding(KeybindingLabels.fromUserSettingsLabel(key || rawKeyBinding.key)); + const keyBinding = createKeybinding(KeybindingIO.readKeybinding(key || rawKeyBinding.key)); const resolvedKeybinding = this.keybindingService.resolveKeybinding(keyBinding); const result = resolvedKeybinding.getLabel(); return result === 'unknown' ? null : result; diff --git a/src/vs/workbench/parts/update/electron-browser/update.ts b/src/vs/workbench/parts/update/electron-browser/update.ts index 39893f1f12dfad882a7f945b1cfe02032022f603..4d260033f67e21fc7f50069c84ec9756e39f77f2 100644 --- a/src/vs/workbench/parts/update/electron-browser/update.ts +++ b/src/vs/workbench/parts/update/electron-browser/update.ts @@ -20,7 +20,7 @@ import { IRequestService } from 'vs/platform/request/node/request'; import { asText } from 'vs/base/node/request'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { createKeybinding } from 'vs/base/common/keyCodes'; -import { KeybindingLabels } from 'vs/platform/keybinding/common/keybindingLabels'; +import { KeybindingIO } from 'vs/platform/keybinding/common/keybindingIO'; import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; @@ -73,7 +73,7 @@ export function loadReleaseNotes(accessor: ServicesAccessor, version: string): T }; const kbstyle = (match: string, kb: string) => { - const code = KeybindingLabels.fromUserSettingsLabel(kb); + const code = KeybindingIO.readKeybinding(kb); if (!code) { return unassigned;