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

mark KeyCode enum as const

上级 6ab796c6
...@@ -39,7 +39,8 @@ declare module monaco { ...@@ -39,7 +39,8 @@ declare module monaco {
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise #include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise
#include(vs/base/common/cancellation): CancellationTokenSource, CancellationToken #include(vs/base/common/cancellation): CancellationTokenSource, CancellationToken
#include(vs/base/common/uri): URI #include(vs/base/common/uri): URI
#include(vs/base/common/keyCodes): KeyCode, KeyMod #include(vs/editor/common/standalone/standaloneBase): KeyCode
#include(vs/base/common/keyCodes): KeyMod
#include(vs/base/common/htmlContent): MarkedString #include(vs/base/common/htmlContent): MarkedString
#include(vs/base/browser/keyboardEvent): IKeyboardEvent #include(vs/base/browser/keyboardEvent): IKeyboardEvent
#include(vs/base/browser/mouseEvent): IMouseEvent #include(vs/base/browser/mouseEvent): IMouseEvent
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'use strict'; 'use strict';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; import {KeyCode, KeyCodeUtils, KeyMod} from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform'; import * as platform from 'vs/base/common/platform';
import * as browser from 'vs/base/browser/browser'; import * as browser from 'vs/base/browser/browser';
...@@ -161,7 +161,7 @@ let extractKeyCode = function extractKeyCode(e:KeyboardEvent): KeyCode { ...@@ -161,7 +161,7 @@ let extractKeyCode = function extractKeyCode(e:KeyboardEvent): KeyCode {
if (e.charCode) { if (e.charCode) {
// "keypress" events mostly // "keypress" events mostly
let char = String.fromCharCode(e.charCode).toUpperCase(); let char = String.fromCharCode(e.charCode).toUpperCase();
return KeyCode.fromString(char); return KeyCodeUtils.fromString(char);
} }
return lookupKeyCode(e); return lookupKeyCode(e);
}; };
......
...@@ -19,181 +19,182 @@ export interface ISimplifiedPlatform { ...@@ -19,181 +19,182 @@ export interface ISimplifiedPlatform {
* Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx * Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
* But these are "more general", as they should work across browsers & OS`s. * But these are "more general", as they should work across browsers & OS`s.
*/ */
export enum KeyCode { export const enum KeyCode {
/** /**
* Placed first to cover the 0 value of the enum. * Placed first to cover the 0 value of the enum.
*/ */
Unknown, Unknown = 0,
Backspace, Backspace = 1,
Tab, Tab = 2,
Enter, Enter = 3,
Shift, Shift = 4,
Ctrl, Ctrl = 5,
Alt, Alt = 6,
PauseBreak, PauseBreak = 7,
CapsLock, CapsLock = 8,
Escape, Escape = 9,
Space, Space = 10,
PageUp, PageUp = 11,
PageDown, PageDown = 12,
End, End = 13,
Home, Home = 14,
LeftArrow, LeftArrow = 15,
UpArrow, UpArrow = 16,
RightArrow, RightArrow = 17,
DownArrow, DownArrow = 18,
Insert, Insert = 19,
Delete, Delete = 20,
KEY_0, KEY_0 = 21,
KEY_1, KEY_1 = 22,
KEY_2, KEY_2 = 23,
KEY_3, KEY_3 = 24,
KEY_4, KEY_4 = 25,
KEY_5, KEY_5 = 26,
KEY_6, KEY_6 = 27,
KEY_7, KEY_7 = 28,
KEY_8, KEY_8 = 29,
KEY_9, KEY_9 = 30,
KEY_A, KEY_A = 31,
KEY_B, KEY_B = 32,
KEY_C, KEY_C = 33,
KEY_D, KEY_D = 34,
KEY_E, KEY_E = 35,
KEY_F, KEY_F = 36,
KEY_G, KEY_G = 37,
KEY_H, KEY_H = 38,
KEY_I, KEY_I = 39,
KEY_J, KEY_J = 40,
KEY_K, KEY_K = 41,
KEY_L, KEY_L = 42,
KEY_M, KEY_M = 43,
KEY_N, KEY_N = 44,
KEY_O, KEY_O = 45,
KEY_P, KEY_P = 46,
KEY_Q, KEY_Q = 47,
KEY_R, KEY_R = 48,
KEY_S, KEY_S = 49,
KEY_T, KEY_T = 50,
KEY_U, KEY_U = 51,
KEY_V, KEY_V = 52,
KEY_W, KEY_W = 53,
KEY_X, KEY_X = 54,
KEY_Y, KEY_Y = 55,
KEY_Z, KEY_Z = 56,
Meta, Meta = 57,
ContextMenu, ContextMenu = 58,
F1, F1 = 59,
F2, F2 = 60,
F3, F3 = 61,
F4, F4 = 62,
F5, F5 = 63,
F6, F6 = 64,
F7, F7 = 65,
F8, F8 = 66,
F9, F9 = 67,
F10, F10 = 68,
F11, F11 = 69,
F12, F12 = 70,
F13, F13 = 71,
F14, F14 = 72,
F15, F15 = 73,
F16, F16 = 74,
F17, F17 = 75,
F18, F18 = 76,
F19, F19 = 77,
NumLock, NumLock = 78,
ScrollLock, ScrollLock = 79,
/** /**
* Used for miscellaneous characters; it can vary by keyboard. * Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ';:' key * For the US standard keyboard, the ';:' key
*/ */
US_SEMICOLON, US_SEMICOLON = 80,
/** /**
* For any country/region, the '+' key * For any country/region, the '+' key
* For the US standard keyboard, the '=+' key * For the US standard keyboard, the '=+' key
*/ */
US_EQUAL, US_EQUAL = 81,
/** /**
* For any country/region, the ',' key * For any country/region, the ',' key
* For the US standard keyboard, the ',<' key * For the US standard keyboard, the ',<' key
*/ */
US_COMMA, US_COMMA = 82,
/** /**
* For any country/region, the '-' key * For any country/region, the '-' key
* For the US standard keyboard, the '-_' key * For the US standard keyboard, the '-_' key
*/ */
US_MINUS, US_MINUS = 83,
/** /**
* For any country/region, the '.' key * For any country/region, the '.' key
* For the US standard keyboard, the '.>' key * For the US standard keyboard, the '.>' key
*/ */
US_DOT, US_DOT = 84,
/** /**
* Used for miscellaneous characters; it can vary by keyboard. * Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '/?' key * For the US standard keyboard, the '/?' key
*/ */
US_SLASH, US_SLASH = 85,
/** /**
* Used for miscellaneous characters; it can vary by keyboard. * Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '`~' key * For the US standard keyboard, the '`~' key
*/ */
US_BACKTICK, US_BACKTICK = 86,
/** /**
* Used for miscellaneous characters; it can vary by keyboard. * Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '[{' key * For the US standard keyboard, the '[{' key
*/ */
US_OPEN_SQUARE_BRACKET, US_OPEN_SQUARE_BRACKET = 87,
/** /**
* Used for miscellaneous characters; it can vary by keyboard. * Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '\|' key * For the US standard keyboard, the '\|' key
*/ */
US_BACKSLASH, US_BACKSLASH = 88,
/** /**
* Used for miscellaneous characters; it can vary by keyboard. * Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ']}' key * For the US standard keyboard, the ']}' key
*/ */
US_CLOSE_SQUARE_BRACKET, US_CLOSE_SQUARE_BRACKET = 89,
/** /**
* Used for miscellaneous characters; it can vary by keyboard. * Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ''"' key * For the US standard keyboard, the ''"' key
*/ */
US_QUOTE, US_QUOTE = 90,
/** /**
* Used for miscellaneous characters; it can vary by keyboard. * Used for miscellaneous characters; it can vary by keyboard.
*/ */
OEM_8, OEM_8 = 91,
/** /**
* Either the angle bracket key or the backslash key on the RT 102-key keyboard. * Either the angle bracket key or the backslash key on the RT 102-key keyboard.
*/ */
OEM_102, OEM_102 = 92,
NUMPAD_0, // VK_NUMPAD0, 0x60, Numeric keypad 0 key NUMPAD_0 = 93, // VK_NUMPAD0, 0x60, Numeric keypad 0 key
NUMPAD_1, // VK_NUMPAD1, 0x61, Numeric keypad 1 key NUMPAD_1 = 94, // VK_NUMPAD1, 0x61, Numeric keypad 1 key
NUMPAD_2, // VK_NUMPAD2, 0x62, Numeric keypad 2 key NUMPAD_2 = 95, // VK_NUMPAD2, 0x62, Numeric keypad 2 key
NUMPAD_3, // VK_NUMPAD3, 0x63, Numeric keypad 3 key NUMPAD_3 = 96, // VK_NUMPAD3, 0x63, Numeric keypad 3 key
NUMPAD_4, // VK_NUMPAD4, 0x64, Numeric keypad 4 key NUMPAD_4 = 97, // VK_NUMPAD4, 0x64, Numeric keypad 4 key
NUMPAD_5, // VK_NUMPAD5, 0x65, Numeric keypad 5 key NUMPAD_5 = 98, // VK_NUMPAD5, 0x65, Numeric keypad 5 key
NUMPAD_6, // VK_NUMPAD6, 0x66, Numeric keypad 6 key NUMPAD_6 = 99, // VK_NUMPAD6, 0x66, Numeric keypad 6 key
NUMPAD_7, // VK_NUMPAD7, 0x67, Numeric keypad 7 key NUMPAD_7 = 100, // VK_NUMPAD7, 0x67, Numeric keypad 7 key
NUMPAD_8, // VK_NUMPAD8, 0x68, Numeric keypad 8 key NUMPAD_8 = 101, // VK_NUMPAD8, 0x68, Numeric keypad 8 key
NUMPAD_9, // VK_NUMPAD9, 0x69, Numeric keypad 9 key NUMPAD_9 = 102, // VK_NUMPAD9, 0x69, Numeric keypad 9 key
NUMPAD_MULTIPLY, // VK_MULTIPLY, 0x6A, Multiply key NUMPAD_MULTIPLY = 103, // VK_MULTIPLY, 0x6A, Multiply key
NUMPAD_ADD, // VK_ADD, 0x6B, Add key NUMPAD_ADD = 104, // VK_ADD, 0x6B, Add key
NUMPAD_SEPARATOR, // VK_SEPARATOR, 0x6C, Separator key NUMPAD_SEPARATOR = 105, // VK_SEPARATOR, 0x6C, Separator key
NUMPAD_SUBTRACT, // VK_SUBTRACT, 0x6D, Subtract key NUMPAD_SUBTRACT = 106, // VK_SUBTRACT, 0x6D, Subtract key
NUMPAD_DECIMAL, // VK_DECIMAL, 0x6E, Decimal key NUMPAD_DECIMAL = 107, // VK_DECIMAL, 0x6E, Decimal key
NUMPAD_DIVIDE, // VK_DIVIDE, 0x6F, NUMPAD_DIVIDE = 108, // VK_DIVIDE, 0x6F,
/** /**
* Placed last to cover the length of the enum. * Placed last to cover the length of the enum.
* Please do not depend on this value!
*/ */
MAX_VALUE MAX_VALUE
} }
...@@ -403,7 +404,7 @@ let USER_SETTINGS = createMapping((TO_USER_SETTINGS_MAP) => { ...@@ -403,7 +404,7 @@ let USER_SETTINGS = createMapping((TO_USER_SETTINGS_MAP) => {
FROM_USER_SETTINGS_MAP['OEM_102'] = KeyCode.OEM_102; FROM_USER_SETTINGS_MAP['OEM_102'] = KeyCode.OEM_102;
}); });
export namespace KeyCode { export namespace KeyCodeUtils {
export function toString(key:KeyCode): string { export function toString(key:KeyCode): string {
return STRING.fromKeyCode(key); return STRING.fromKeyCode(key);
} }
...@@ -797,7 +798,7 @@ export class ElectronAcceleratorLabelProvider implements IKeyBindingLabelProvide ...@@ -797,7 +798,7 @@ export class ElectronAcceleratorLabelProvider implements IKeyBindingLabelProvide
return 'Right'; return 'Right';
} }
return KeyCode.toString(keyCode); return KeyCodeUtils.toString(keyCode);
} }
} }
...@@ -831,7 +832,7 @@ export class MacUIKeyLabelProvider implements IKeyBindingLabelProvider { ...@@ -831,7 +832,7 @@ export class MacUIKeyLabelProvider implements IKeyBindingLabelProvider {
return MacUIKeyLabelProvider.downArrowUnicodeLabel; return MacUIKeyLabelProvider.downArrowUnicodeLabel;
} }
return KeyCode.toString(keyCode); return KeyCodeUtils.toString(keyCode);
} }
} }
...@@ -849,7 +850,7 @@ export class AriaKeyLabelProvider implements IKeyBindingLabelProvider { ...@@ -849,7 +850,7 @@ export class AriaKeyLabelProvider implements IKeyBindingLabelProvider {
public modifierSeparator = '+'; public modifierSeparator = '+';
public getLabelForKey(keyCode:KeyCode): string { public getLabelForKey(keyCode:KeyCode): string {
return KeyCode.toString(keyCode); return KeyCodeUtils.toString(keyCode);
} }
} }
...@@ -867,7 +868,7 @@ export class ClassicUIKeyLabelProvider implements IKeyBindingLabelProvider { ...@@ -867,7 +868,7 @@ export class ClassicUIKeyLabelProvider implements IKeyBindingLabelProvider {
public modifierSeparator = '+'; public modifierSeparator = '+';
public getLabelForKey(keyCode:KeyCode): string { public getLabelForKey(keyCode:KeyCode): string {
return KeyCode.toString(keyCode); return KeyCodeUtils.toString(keyCode);
} }
} }
......
...@@ -65,44 +65,4 @@ suite('keyCodes', () => { ...@@ -65,44 +65,4 @@ suite('keyCodes', () => {
assert.equal(encodedFirstPart, KeyMod.CtrlCmd | KeyCode.KEY_Y, 'first part'); assert.equal(encodedFirstPart, KeyMod.CtrlCmd | KeyCode.KEY_Y, 'first part');
assert.equal(encodedSecondPart, encodedSecondPart, 'chord part'); assert.equal(encodedSecondPart, encodedSecondPart, 'chord part');
}); });
test('getUserSettingsKeybindingRegex', () => {
let regex = new RegExp(Keybinding.getUserSettingsKeybindingRegex());
function testIsGood(userSettingsLabel:string, message:string = userSettingsLabel): void {
let userSettings = '"' + userSettingsLabel.replace(/\\/g, '\\\\') + '"';
let isGood = regex.test(userSettings);
assert.ok(isGood, message);
}
// check that all key codes are covered by the regex
let ignore: boolean[] = [];
ignore[KeyCode.Shift] = true;
ignore[KeyCode.Ctrl] = true;
ignore[KeyCode.Alt] = true;
ignore[KeyCode.Meta] = true;
for (let keyCode = KeyCode.Unknown + 1; keyCode < KeyCode.MAX_VALUE; keyCode++) {
if (ignore[keyCode]) {
continue;
}
let userSettings = Keybinding.toUserSettingsLabel(keyCode);
testIsGood(userSettings, keyCode + ' - ' + KeyCode[keyCode] + ' - ' + userSettings);
}
// one modifier
testIsGood('ctrl+a');
testIsGood('shift+a');
testIsGood('alt+a');
testIsGood('cmd+a');
testIsGood('meta+a');
testIsGood('win+a');
// more modifiers
testIsGood('ctrl+shift+a');
testIsGood('shift+alt+a');
testIsGood('ctrl+shift+alt+a');
// chords
testIsGood('ctrl+a ctrl+a');
});
}); });
...@@ -243,7 +243,7 @@ export function colorizeModelLine(model:IModel, lineNumber:number, tabSize:numbe ...@@ -243,7 +243,7 @@ export function colorizeModelLine(model:IModel, lineNumber:number, tabSize:numbe
export function createMonacoEditorAPI(): typeof monaco.editor { export function createMonacoEditorAPI(): typeof monaco.editor {
return { return {
// methods // methods
create: create, create: <any>create,
createDiffEditor: createDiffEditor, createDiffEditor: createDiffEditor,
createDiffNavigator: createDiffNavigator, createDiffNavigator: createDiffNavigator,
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'use strict'; 'use strict';
import {Emitter} from 'vs/base/common/event'; import {Emitter} from 'vs/base/common/event';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; import {KeyMod} from 'vs/base/common/keyCodes';
import {Position} from 'vs/editor/common/core/position'; import {Position} from 'vs/editor/common/core/position';
import {Range} from 'vs/editor/common/core/range'; import {Range} from 'vs/editor/common/core/range';
import {Selection, SelectionDirection} from 'vs/editor/common/core/selection'; import {Selection, SelectionDirection} from 'vs/editor/common/core/selection';
...@@ -14,6 +14,184 @@ import {CancellationTokenSource} from 'vs/base/common/cancellation'; ...@@ -14,6 +14,184 @@ import {CancellationTokenSource} from 'vs/base/common/cancellation';
import Severity from 'vs/base/common/severity'; import Severity from 'vs/base/common/severity';
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
// --------------------------------------------
// This is repeated here so it can be exported
// --------------------------------------------
/**
* Virtual Key Codes, the value does not hold any inherent meaning.
* Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
* But these are "more general", as they should work across browsers & OS`s.
*/
export enum KeyCode {
/**
* Placed first to cover the 0 value of the enum.
*/
Unknown = 0,
Backspace = 1,
Tab = 2,
Enter = 3,
Shift = 4,
Ctrl = 5,
Alt = 6,
PauseBreak = 7,
CapsLock = 8,
Escape = 9,
Space = 10,
PageUp = 11,
PageDown = 12,
End = 13,
Home = 14,
LeftArrow = 15,
UpArrow = 16,
RightArrow = 17,
DownArrow = 18,
Insert = 19,
Delete = 20,
KEY_0 = 21,
KEY_1 = 22,
KEY_2 = 23,
KEY_3 = 24,
KEY_4 = 25,
KEY_5 = 26,
KEY_6 = 27,
KEY_7 = 28,
KEY_8 = 29,
KEY_9 = 30,
KEY_A = 31,
KEY_B = 32,
KEY_C = 33,
KEY_D = 34,
KEY_E = 35,
KEY_F = 36,
KEY_G = 37,
KEY_H = 38,
KEY_I = 39,
KEY_J = 40,
KEY_K = 41,
KEY_L = 42,
KEY_M = 43,
KEY_N = 44,
KEY_O = 45,
KEY_P = 46,
KEY_Q = 47,
KEY_R = 48,
KEY_S = 49,
KEY_T = 50,
KEY_U = 51,
KEY_V = 52,
KEY_W = 53,
KEY_X = 54,
KEY_Y = 55,
KEY_Z = 56,
Meta = 57,
ContextMenu = 58,
F1 = 59,
F2 = 60,
F3 = 61,
F4 = 62,
F5 = 63,
F6 = 64,
F7 = 65,
F8 = 66,
F9 = 67,
F10 = 68,
F11 = 69,
F12 = 70,
F13 = 71,
F14 = 72,
F15 = 73,
F16 = 74,
F17 = 75,
F18 = 76,
F19 = 77,
NumLock = 78,
ScrollLock = 79,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ';:' key
*/
US_SEMICOLON = 80,
/**
* For any country/region, the '+' key
* For the US standard keyboard, the '=+' key
*/
US_EQUAL = 81,
/**
* For any country/region, the ',' key
* For the US standard keyboard, the ',<' key
*/
US_COMMA = 82,
/**
* For any country/region, the '-' key
* For the US standard keyboard, the '-_' key
*/
US_MINUS = 83,
/**
* For any country/region, the '.' key
* For the US standard keyboard, the '.>' key
*/
US_DOT = 84,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '/?' key
*/
US_SLASH = 85,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '`~' key
*/
US_BACKTICK = 86,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '[{' key
*/
US_OPEN_SQUARE_BRACKET = 87,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '\|' key
*/
US_BACKSLASH = 88,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ']}' key
*/
US_CLOSE_SQUARE_BRACKET = 89,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ''"' key
*/
US_QUOTE = 90,
/**
* Used for miscellaneous characters; it can vary by keyboard.
*/
OEM_8 = 91,
/**
* Either the angle bracket key or the backslash key on the RT 102-key keyboard.
*/
OEM_102 = 92,
NUMPAD_0 = 93,
NUMPAD_1 = 94,
NUMPAD_2 = 95,
NUMPAD_3 = 96,
NUMPAD_4 = 97,
NUMPAD_5 = 98,
NUMPAD_6 = 99,
NUMPAD_7 = 100,
NUMPAD_8 = 101,
NUMPAD_9 = 102,
NUMPAD_MULTIPLY = 103,
NUMPAD_ADD = 104,
NUMPAD_SEPARATOR = 105,
NUMPAD_SUBTRACT = 106,
NUMPAD_DECIMAL = 107,
NUMPAD_DIVIDE = 108,
/**
* Placed last to cover the length of the enum.
* Please do not depend on this value!
*/
MAX_VALUE
}
export function createMonacoBaseAPI(): typeof monaco { export function createMonacoBaseAPI(): typeof monaco {
return { return {
editor: undefined, editor: undefined,
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import {KeyCode as StandaloneKeyCode} from 'vs/editor/common/standalone/standaloneBase';
import {KeyCode as RuntimeKeyCode} from 'vs/base/common/keyCodes';
import {/*KeyCode, KeyMod, BinaryKeybindings,*/ Keybinding} from 'vs/base/common/keyCodes';
suite('KeyCode', () => {
test('is exported correctly in standalone editor', () => {
function assertKeyCode(standalone: StandaloneKeyCode, runtime: RuntimeKeyCode): void {
assert.equal(standalone, runtime);
}
assertKeyCode(StandaloneKeyCode.Unknown, RuntimeKeyCode.Unknown);
assertKeyCode(StandaloneKeyCode.Backspace, RuntimeKeyCode.Backspace);
assertKeyCode(StandaloneKeyCode.Tab, RuntimeKeyCode.Tab);
assertKeyCode(StandaloneKeyCode.Enter, RuntimeKeyCode.Enter);
assertKeyCode(StandaloneKeyCode.Shift, RuntimeKeyCode.Shift);
assertKeyCode(StandaloneKeyCode.Ctrl, RuntimeKeyCode.Ctrl);
assertKeyCode(StandaloneKeyCode.Alt, RuntimeKeyCode.Alt);
assertKeyCode(StandaloneKeyCode.PauseBreak, RuntimeKeyCode.PauseBreak);
assertKeyCode(StandaloneKeyCode.CapsLock, RuntimeKeyCode.CapsLock);
assertKeyCode(StandaloneKeyCode.Escape, RuntimeKeyCode.Escape);
assertKeyCode(StandaloneKeyCode.Space, RuntimeKeyCode.Space);
assertKeyCode(StandaloneKeyCode.PageUp, RuntimeKeyCode.PageUp);
assertKeyCode(StandaloneKeyCode.PageDown, RuntimeKeyCode.PageDown);
assertKeyCode(StandaloneKeyCode.End, RuntimeKeyCode.End);
assertKeyCode(StandaloneKeyCode.Home, RuntimeKeyCode.Home);
assertKeyCode(StandaloneKeyCode.LeftArrow, RuntimeKeyCode.LeftArrow);
assertKeyCode(StandaloneKeyCode.UpArrow, RuntimeKeyCode.UpArrow);
assertKeyCode(StandaloneKeyCode.RightArrow, RuntimeKeyCode.RightArrow);
assertKeyCode(StandaloneKeyCode.DownArrow, RuntimeKeyCode.DownArrow);
assertKeyCode(StandaloneKeyCode.Insert, RuntimeKeyCode.Insert);
assertKeyCode(StandaloneKeyCode.Delete, RuntimeKeyCode.Delete);
assertKeyCode(StandaloneKeyCode.KEY_0, RuntimeKeyCode.KEY_0);
assertKeyCode(StandaloneKeyCode.KEY_1, RuntimeKeyCode.KEY_1);
assertKeyCode(StandaloneKeyCode.KEY_2, RuntimeKeyCode.KEY_2);
assertKeyCode(StandaloneKeyCode.KEY_3, RuntimeKeyCode.KEY_3);
assertKeyCode(StandaloneKeyCode.KEY_4, RuntimeKeyCode.KEY_4);
assertKeyCode(StandaloneKeyCode.KEY_5, RuntimeKeyCode.KEY_5);
assertKeyCode(StandaloneKeyCode.KEY_6, RuntimeKeyCode.KEY_6);
assertKeyCode(StandaloneKeyCode.KEY_7, RuntimeKeyCode.KEY_7);
assertKeyCode(StandaloneKeyCode.KEY_8, RuntimeKeyCode.KEY_8);
assertKeyCode(StandaloneKeyCode.KEY_9, RuntimeKeyCode.KEY_9);
assertKeyCode(StandaloneKeyCode.KEY_A, RuntimeKeyCode.KEY_A);
assertKeyCode(StandaloneKeyCode.KEY_B, RuntimeKeyCode.KEY_B);
assertKeyCode(StandaloneKeyCode.KEY_C, RuntimeKeyCode.KEY_C);
assertKeyCode(StandaloneKeyCode.KEY_D, RuntimeKeyCode.KEY_D);
assertKeyCode(StandaloneKeyCode.KEY_E, RuntimeKeyCode.KEY_E);
assertKeyCode(StandaloneKeyCode.KEY_F, RuntimeKeyCode.KEY_F);
assertKeyCode(StandaloneKeyCode.KEY_G, RuntimeKeyCode.KEY_G);
assertKeyCode(StandaloneKeyCode.KEY_H, RuntimeKeyCode.KEY_H);
assertKeyCode(StandaloneKeyCode.KEY_I, RuntimeKeyCode.KEY_I);
assertKeyCode(StandaloneKeyCode.KEY_J, RuntimeKeyCode.KEY_J);
assertKeyCode(StandaloneKeyCode.KEY_K, RuntimeKeyCode.KEY_K);
assertKeyCode(StandaloneKeyCode.KEY_L, RuntimeKeyCode.KEY_L);
assertKeyCode(StandaloneKeyCode.KEY_M, RuntimeKeyCode.KEY_M);
assertKeyCode(StandaloneKeyCode.KEY_N, RuntimeKeyCode.KEY_N);
assertKeyCode(StandaloneKeyCode.KEY_O, RuntimeKeyCode.KEY_O);
assertKeyCode(StandaloneKeyCode.KEY_P, RuntimeKeyCode.KEY_P);
assertKeyCode(StandaloneKeyCode.KEY_Q, RuntimeKeyCode.KEY_Q);
assertKeyCode(StandaloneKeyCode.KEY_R, RuntimeKeyCode.KEY_R);
assertKeyCode(StandaloneKeyCode.KEY_S, RuntimeKeyCode.KEY_S);
assertKeyCode(StandaloneKeyCode.KEY_T, RuntimeKeyCode.KEY_T);
assertKeyCode(StandaloneKeyCode.KEY_U, RuntimeKeyCode.KEY_U);
assertKeyCode(StandaloneKeyCode.KEY_V, RuntimeKeyCode.KEY_V);
assertKeyCode(StandaloneKeyCode.KEY_W, RuntimeKeyCode.KEY_W);
assertKeyCode(StandaloneKeyCode.KEY_X, RuntimeKeyCode.KEY_X);
assertKeyCode(StandaloneKeyCode.KEY_Y, RuntimeKeyCode.KEY_Y);
assertKeyCode(StandaloneKeyCode.KEY_Z, RuntimeKeyCode.KEY_Z);
assertKeyCode(StandaloneKeyCode.Meta, RuntimeKeyCode.Meta);
assertKeyCode(StandaloneKeyCode.ContextMenu, RuntimeKeyCode.ContextMenu);
assertKeyCode(StandaloneKeyCode.F1, RuntimeKeyCode.F1);
assertKeyCode(StandaloneKeyCode.F2, RuntimeKeyCode.F2);
assertKeyCode(StandaloneKeyCode.F3, RuntimeKeyCode.F3);
assertKeyCode(StandaloneKeyCode.F4, RuntimeKeyCode.F4);
assertKeyCode(StandaloneKeyCode.F5, RuntimeKeyCode.F5);
assertKeyCode(StandaloneKeyCode.F6, RuntimeKeyCode.F6);
assertKeyCode(StandaloneKeyCode.F7, RuntimeKeyCode.F7);
assertKeyCode(StandaloneKeyCode.F8, RuntimeKeyCode.F8);
assertKeyCode(StandaloneKeyCode.F9, RuntimeKeyCode.F9);
assertKeyCode(StandaloneKeyCode.F10, RuntimeKeyCode.F10);
assertKeyCode(StandaloneKeyCode.F11, RuntimeKeyCode.F11);
assertKeyCode(StandaloneKeyCode.F12, RuntimeKeyCode.F12);
assertKeyCode(StandaloneKeyCode.F13, RuntimeKeyCode.F13);
assertKeyCode(StandaloneKeyCode.F14, RuntimeKeyCode.F14);
assertKeyCode(StandaloneKeyCode.F15, RuntimeKeyCode.F15);
assertKeyCode(StandaloneKeyCode.F16, RuntimeKeyCode.F16);
assertKeyCode(StandaloneKeyCode.F17, RuntimeKeyCode.F17);
assertKeyCode(StandaloneKeyCode.F18, RuntimeKeyCode.F18);
assertKeyCode(StandaloneKeyCode.F19, RuntimeKeyCode.F19);
assertKeyCode(StandaloneKeyCode.NumLock, RuntimeKeyCode.NumLock);
assertKeyCode(StandaloneKeyCode.ScrollLock, RuntimeKeyCode.ScrollLock);
assertKeyCode(StandaloneKeyCode.US_SEMICOLON, RuntimeKeyCode.US_SEMICOLON);
assertKeyCode(StandaloneKeyCode.US_EQUAL, RuntimeKeyCode.US_EQUAL);
assertKeyCode(StandaloneKeyCode.US_COMMA, RuntimeKeyCode.US_COMMA);
assertKeyCode(StandaloneKeyCode.US_MINUS, RuntimeKeyCode.US_MINUS);
assertKeyCode(StandaloneKeyCode.US_DOT, RuntimeKeyCode.US_DOT);
assertKeyCode(StandaloneKeyCode.US_SLASH, RuntimeKeyCode.US_SLASH);
assertKeyCode(StandaloneKeyCode.US_BACKTICK, RuntimeKeyCode.US_BACKTICK);
assertKeyCode(StandaloneKeyCode.US_OPEN_SQUARE_BRACKET, RuntimeKeyCode.US_OPEN_SQUARE_BRACKET);
assertKeyCode(StandaloneKeyCode.US_BACKSLASH, RuntimeKeyCode.US_BACKSLASH);
assertKeyCode(StandaloneKeyCode.US_CLOSE_SQUARE_BRACKET, RuntimeKeyCode.US_CLOSE_SQUARE_BRACKET);
assertKeyCode(StandaloneKeyCode.US_QUOTE, RuntimeKeyCode.US_QUOTE);
assertKeyCode(StandaloneKeyCode.OEM_8, RuntimeKeyCode.OEM_8);
assertKeyCode(StandaloneKeyCode.OEM_102, RuntimeKeyCode.OEM_102);
assertKeyCode(StandaloneKeyCode.NUMPAD_0, RuntimeKeyCode.NUMPAD_0);
assertKeyCode(StandaloneKeyCode.NUMPAD_1, RuntimeKeyCode.NUMPAD_1);
assertKeyCode(StandaloneKeyCode.NUMPAD_2, RuntimeKeyCode.NUMPAD_2);
assertKeyCode(StandaloneKeyCode.NUMPAD_3, RuntimeKeyCode.NUMPAD_3);
assertKeyCode(StandaloneKeyCode.NUMPAD_4, RuntimeKeyCode.NUMPAD_4);
assertKeyCode(StandaloneKeyCode.NUMPAD_5, RuntimeKeyCode.NUMPAD_5);
assertKeyCode(StandaloneKeyCode.NUMPAD_6, RuntimeKeyCode.NUMPAD_6);
assertKeyCode(StandaloneKeyCode.NUMPAD_7, RuntimeKeyCode.NUMPAD_7);
assertKeyCode(StandaloneKeyCode.NUMPAD_8, RuntimeKeyCode.NUMPAD_8);
assertKeyCode(StandaloneKeyCode.NUMPAD_9, RuntimeKeyCode.NUMPAD_9);
assertKeyCode(StandaloneKeyCode.NUMPAD_MULTIPLY, RuntimeKeyCode.NUMPAD_MULTIPLY);
assertKeyCode(StandaloneKeyCode.NUMPAD_ADD, RuntimeKeyCode.NUMPAD_ADD);
assertKeyCode(StandaloneKeyCode.NUMPAD_SEPARATOR, RuntimeKeyCode.NUMPAD_SEPARATOR);
assertKeyCode(StandaloneKeyCode.NUMPAD_SUBTRACT, RuntimeKeyCode.NUMPAD_SUBTRACT);
assertKeyCode(StandaloneKeyCode.NUMPAD_DECIMAL, RuntimeKeyCode.NUMPAD_DECIMAL);
assertKeyCode(StandaloneKeyCode.NUMPAD_DIVIDE, RuntimeKeyCode.NUMPAD_DIVIDE);
assertKeyCode(StandaloneKeyCode.MAX_VALUE, RuntimeKeyCode.MAX_VALUE);
});
test('getUserSettingsKeybindingRegex', () => {
let regex = new RegExp(Keybinding.getUserSettingsKeybindingRegex());
function testIsGood(userSettingsLabel:string, message:string = userSettingsLabel): void {
let userSettings = '"' + userSettingsLabel.replace(/\\/g, '\\\\') + '"';
let isGood = regex.test(userSettings);
assert.ok(isGood, message);
}
// check that all key codes are covered by the regex
let ignore: boolean[] = [];
ignore[RuntimeKeyCode.Shift] = true;
ignore[RuntimeKeyCode.Ctrl] = true;
ignore[RuntimeKeyCode.Alt] = true;
ignore[RuntimeKeyCode.Meta] = true;
for (let keyCode = RuntimeKeyCode.Unknown + 1; keyCode < RuntimeKeyCode.MAX_VALUE; keyCode++) {
if (ignore[keyCode]) {
continue;
}
let userSettings = Keybinding.toUserSettingsLabel(keyCode);
testIsGood(userSettings, keyCode + ' - ' + StandaloneKeyCode[keyCode] + ' - ' + userSettings);
}
// one modifier
testIsGood('ctrl+a');
testIsGood('shift+a');
testIsGood('alt+a');
testIsGood('cmd+a');
testIsGood('meta+a');
testIsGood('win+a');
// more modifiers
testIsGood('ctrl+shift+a');
testIsGood('shift+alt+a');
testIsGood('ctrl+shift+alt+a');
// chords
testIsGood('ctrl+a ctrl+a');
});
});
\ No newline at end of file
...@@ -170,7 +170,6 @@ declare module monaco { ...@@ -170,7 +170,6 @@ declare module monaco {
toJSON(): any; toJSON(): any;
static revive(data: any): Uri; static revive(data: any): Uri;
} }
/** /**
* Virtual Key Codes, the value does not hold any inherent meaning. * Virtual Key Codes, the value does not hold any inherent meaning.
* Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx * Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
...@@ -341,6 +340,7 @@ declare module monaco { ...@@ -341,6 +340,7 @@ declare module monaco {
NUMPAD_DIVIDE = 108, NUMPAD_DIVIDE = 108,
/** /**
* Placed last to cover the length of the enum. * Placed last to cover the length of the enum.
* Please do not depend on this value!
*/ */
MAX_VALUE = 109, MAX_VALUE = 109,
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
'use strict'; 'use strict';
import {BinaryKeybindings, KeyCode} from 'vs/base/common/keyCodes'; import {BinaryKeybindings, KeyCodeUtils} from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform'; import * as platform from 'vs/base/common/platform';
import {IKeybindingItem, IKeybindings} from 'vs/platform/keybinding/common/keybinding'; import {IKeybindingItem, IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey'; import {ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey';
...@@ -105,7 +105,7 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry { ...@@ -105,7 +105,7 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry {
private registerDefaultKeybinding(keybinding: number, commandId: string, weight1: number, weight2: number, when: ContextKeyExpr): void { private registerDefaultKeybinding(keybinding: number, commandId: string, weight1: number, weight2: number, when: ContextKeyExpr): void {
if (platform.isWindows) { if (platform.isWindows) {
if (BinaryKeybindings.hasCtrlCmd(keybinding) && !BinaryKeybindings.hasShift(keybinding) && BinaryKeybindings.hasAlt(keybinding) && !BinaryKeybindings.hasWinCtrl(keybinding)) { if (BinaryKeybindings.hasCtrlCmd(keybinding) && !BinaryKeybindings.hasShift(keybinding) && BinaryKeybindings.hasAlt(keybinding) && !BinaryKeybindings.hasWinCtrl(keybinding)) {
if (/^[A-Z0-9\[\]\|\;\'\,\.\/\`]$/.test(KeyCode.toString(BinaryKeybindings.extractKeyCode(keybinding)))) { if (/^[A-Z0-9\[\]\|\;\'\,\.\/\`]$/.test(KeyCodeUtils.toString(BinaryKeybindings.extractKeyCode(keybinding)))) {
console.warn('Ctrl+Alt+ keybindings should not be used by default under Windows. Offender: ', keybinding, ' for ', commandId); console.warn('Ctrl+Alt+ keybindings should not be used by default under Windows. Offender: ', keybinding, ' for ', commandId);
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'use strict'; 'use strict';
import * as nativeKeymap from 'native-keymap'; import * as nativeKeymap from 'native-keymap';
import {KeyCode, IKeyBindingLabelProvider, MacUIKeyLabelProvider, ClassicUIKeyLabelProvider, AriaKeyLabelProvider} from 'vs/base/common/keyCodes'; import {KeyCode, KeyCodeUtils, IKeyBindingLabelProvider, MacUIKeyLabelProvider, ClassicUIKeyLabelProvider, AriaKeyLabelProvider} from 'vs/base/common/keyCodes';
import {lookupKeyCode, setExtractKeyCode} from 'vs/base/browser/keyboardEvent'; import {lookupKeyCode, setExtractKeyCode} from 'vs/base/browser/keyboardEvent';
import Platform = require('vs/base/common/platform'); import Platform = require('vs/base/common/platform');
...@@ -308,7 +308,7 @@ setExtractKeyCode((e:KeyboardEvent) => { ...@@ -308,7 +308,7 @@ setExtractKeyCode((e:KeyboardEvent) => {
if (e.charCode) { if (e.charCode) {
// "keypress" events mostly // "keypress" events mostly
let char = String.fromCharCode(e.charCode).toUpperCase(); let char = String.fromCharCode(e.charCode).toUpperCase();
return KeyCode.fromString(char); return KeyCodeUtils.fromString(char);
} }
if (Platform.isMacintosh && _b24_interestingVirtualKeyCodes[e.keyCode] && typeof (<any>e).keyIdentifier === 'string') { if (Platform.isMacintosh && _b24_interestingVirtualKeyCodes[e.keyCode] && typeof (<any>e).keyIdentifier === 'string') {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册