提交 071ccc6d 编写于 作者: A Alex Dima

Move keybinding reading out of keybindingLabel

上级 95844db8
......@@ -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);
}
}
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册