@codingame/monaco-vscode-keybindings-service-override 5.2.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,14 @@
1
- import { KeyCodeUtils, IMMUTABLE_CODE_TO_KEY_CODE, ScanCodeUtils, NATIVE_WINDOWS_KEY_CODE_TO_KEY_CODE } from 'vscode/vscode/vs/base/common/keyCodes';
1
+ import { CharCode } from 'vscode/vscode/vs/base/common/charCode';
2
+ import { KeyCodeUtils, KeyCode, ScanCode, IMMUTABLE_CODE_TO_KEY_CODE, ScanCodeUtils, NATIVE_WINDOWS_KEY_CODE_TO_KEY_CODE } from 'vscode/vscode/vs/base/common/keyCodes';
2
3
  import { ScanCodeChord, KeyCodeChord } from 'vscode/vscode/vs/base/common/keybindings';
3
4
  import { UILabelProvider } from 'vscode/vscode/vs/base/common/keybindingLabels';
5
+ import { OperatingSystem } from 'vscode/vscode/vs/base/common/platform';
4
6
  import { BaseResolvedKeybinding } from 'vscode/vscode/vs/platform/keybinding/common/baseResolvedKeybinding';
5
7
  import { toEmptyArrayIfContainsNull } from 'vscode/vscode/vs/platform/keybinding/common/resolvedKeybindingItem';
6
8
 
7
9
  class WindowsNativeResolvedKeybinding extends BaseResolvedKeybinding {
8
10
  constructor(mapper, chords) {
9
- super(1 , chords);
11
+ super(OperatingSystem.Windows, chords);
10
12
  this._mapper = mapper;
11
13
  }
12
14
  _getLabel(chord) {
@@ -44,10 +46,10 @@ class WindowsNativeResolvedKeybinding extends BaseResolvedKeybinding {
44
46
  return this.__isWYSIWYG(chord.keyCode);
45
47
  }
46
48
  __isWYSIWYG(keyCode) {
47
- if (keyCode === 15
48
- || keyCode === 16
49
- || keyCode === 17
50
- || keyCode === 18 ) {
49
+ if (keyCode === KeyCode.LeftArrow
50
+ || keyCode === KeyCode.UpArrow
51
+ || keyCode === KeyCode.RightArrow
52
+ || keyCode === KeyCode.DownArrow) {
51
53
  return true;
52
54
  }
53
55
  const ariaLabel = this._mapper.getAriaLabelForKeyCode(keyCode);
@@ -75,16 +77,16 @@ class WindowsNativeResolvedKeybinding extends BaseResolvedKeybinding {
75
77
  return result;
76
78
  }
77
79
  _getSingleModifierChordDispatch(chord) {
78
- if (chord.keyCode === 5 && !chord.shiftKey && !chord.altKey && !chord.metaKey) {
80
+ if (chord.keyCode === KeyCode.Ctrl && !chord.shiftKey && !chord.altKey && !chord.metaKey) {
79
81
  return 'ctrl';
80
82
  }
81
- if (chord.keyCode === 4 && !chord.ctrlKey && !chord.altKey && !chord.metaKey) {
83
+ if (chord.keyCode === KeyCode.Shift && !chord.ctrlKey && !chord.altKey && !chord.metaKey) {
82
84
  return 'shift';
83
85
  }
84
- if (chord.keyCode === 6 && !chord.ctrlKey && !chord.shiftKey && !chord.metaKey) {
86
+ if (chord.keyCode === KeyCode.Alt && !chord.ctrlKey && !chord.shiftKey && !chord.metaKey) {
85
87
  return 'alt';
86
88
  }
87
- if (chord.keyCode === 57 && !chord.ctrlKey && !chord.shiftKey && !chord.altKey) {
89
+ if (chord.keyCode === KeyCode.Meta && !chord.ctrlKey && !chord.shiftKey && !chord.altKey) {
88
90
  return 'meta';
89
91
  }
90
92
  return null;
@@ -120,10 +122,10 @@ class WindowsKeyboardMapper {
120
122
  this._scanCodeToKeyCode = [];
121
123
  this._keyCodeToLabel = [];
122
124
  this._keyCodeExists = [];
123
- this._keyCodeToLabel[0 ] = ( KeyCodeUtils.toString(0 ));
124
- for (let scanCode = 0 ; scanCode < 193 ; scanCode++) {
125
+ this._keyCodeToLabel[KeyCode.Unknown] = ( KeyCodeUtils.toString(KeyCode.Unknown));
126
+ for (let scanCode = ScanCode.None; scanCode < ScanCode.MAX_VALUE; scanCode++) {
125
127
  const immutableKeyCode = IMMUTABLE_CODE_TO_KEY_CODE[scanCode];
126
- if (immutableKeyCode !== -1 ) {
128
+ if (immutableKeyCode !== KeyCode.DependsOnKbLayout) {
127
129
  this._scanCodeToKeyCode[scanCode] = immutableKeyCode;
128
130
  this._keyCodeToLabel[immutableKeyCode] = ( KeyCodeUtils.toString(immutableKeyCode));
129
131
  this._keyCodeExists[immutableKeyCode] = true;
@@ -135,17 +137,17 @@ class WindowsKeyboardMapper {
135
137
  for (const strCode in rawMappings) {
136
138
  if (rawMappings.hasOwnProperty(strCode)) {
137
139
  const scanCode = ScanCodeUtils.toEnum(strCode);
138
- if (scanCode === 0 ) {
140
+ if (scanCode === ScanCode.None) {
139
141
  continue;
140
142
  }
141
143
  const rawMapping = rawMappings[strCode];
142
144
  const immutableKeyCode = IMMUTABLE_CODE_TO_KEY_CODE[scanCode];
143
- if (immutableKeyCode !== -1 ) {
144
- const keyCode = NATIVE_WINDOWS_KEY_CODE_TO_KEY_CODE[rawMapping.vkey] || 0 ;
145
- if (keyCode === 0 || immutableKeyCode === keyCode) {
145
+ if (immutableKeyCode !== KeyCode.DependsOnKbLayout) {
146
+ const keyCode = NATIVE_WINDOWS_KEY_CODE_TO_KEY_CODE[rawMapping.vkey] || KeyCode.Unknown;
147
+ if (keyCode === KeyCode.Unknown || immutableKeyCode === keyCode) {
146
148
  continue;
147
149
  }
148
- if (scanCode !== 134 ) {
150
+ if (scanCode !== ScanCode.NumpadComma) {
149
151
  continue;
150
152
  }
151
153
  }
@@ -153,7 +155,7 @@ class WindowsKeyboardMapper {
153
155
  const withShift = rawMapping.withShift;
154
156
  const withAltGr = rawMapping.withAltGr;
155
157
  const withShiftAltGr = rawMapping.withShiftAltGr;
156
- const keyCode = NATIVE_WINDOWS_KEY_CODE_TO_KEY_CODE[rawMapping.vkey] || 0 ;
158
+ const keyCode = NATIVE_WINDOWS_KEY_CODE_TO_KEY_CODE[rawMapping.vkey] || KeyCode.Unknown;
157
159
  const mapping = {
158
160
  scanCode: scanCode,
159
161
  keyCode: keyCode,
@@ -164,7 +166,7 @@ class WindowsKeyboardMapper {
164
166
  };
165
167
  this._codeInfo[scanCode] = mapping;
166
168
  this._scanCodeToKeyCode[scanCode] = keyCode;
167
- if (keyCode === 0 ) {
169
+ if (keyCode === KeyCode.Unknown) {
168
170
  continue;
169
171
  }
170
172
  this._keyCodeExists[keyCode] = true;
@@ -176,13 +178,13 @@ class WindowsKeyboardMapper {
176
178
  }
177
179
  else {
178
180
  const charCode = value.charCodeAt(0);
179
- if (charCode >= 97 && charCode <= 122 ) {
180
- const upperCaseValue = 65 + ((charCode - 97) );
181
+ if (charCode >= CharCode.a && charCode <= CharCode.z) {
182
+ const upperCaseValue = CharCode.A + (charCode - CharCode.a);
181
183
  producesLetter[upperCaseValue] = true;
182
184
  producesLetters = true;
183
- this._keyCodeToLabel[keyCode] = String.fromCharCode(65 + ((charCode - 97) ));
185
+ this._keyCodeToLabel[keyCode] = String.fromCharCode(CharCode.A + (charCode - CharCode.a));
184
186
  }
185
- else if (charCode >= 65 && charCode <= 90 ) {
187
+ else if (charCode >= CharCode.A && charCode <= CharCode.Z) {
186
188
  producesLetter[charCode] = true;
187
189
  producesLetters = true;
188
190
  this._keyCodeToLabel[keyCode] = value;
@@ -198,59 +200,59 @@ class WindowsKeyboardMapper {
198
200
  this._keyCodeToLabel[keyCode] = String.fromCharCode(charCode);
199
201
  }
200
202
  };
201
- _registerLetterIfMissing(65 , 31 );
202
- _registerLetterIfMissing(66 , 32 );
203
- _registerLetterIfMissing(67 , 33 );
204
- _registerLetterIfMissing(68 , 34 );
205
- _registerLetterIfMissing(69 , 35 );
206
- _registerLetterIfMissing(70 , 36 );
207
- _registerLetterIfMissing(71 , 37 );
208
- _registerLetterIfMissing(72 , 38 );
209
- _registerLetterIfMissing(73 , 39 );
210
- _registerLetterIfMissing(74 , 40 );
211
- _registerLetterIfMissing(75 , 41 );
212
- _registerLetterIfMissing(76 , 42 );
213
- _registerLetterIfMissing(77 , 43 );
214
- _registerLetterIfMissing(78 , 44 );
215
- _registerLetterIfMissing(79 , 45 );
216
- _registerLetterIfMissing(80 , 46 );
217
- _registerLetterIfMissing(81 , 47 );
218
- _registerLetterIfMissing(82 , 48 );
219
- _registerLetterIfMissing(83 , 49 );
220
- _registerLetterIfMissing(84 , 50 );
221
- _registerLetterIfMissing(85 , 51 );
222
- _registerLetterIfMissing(86 , 52 );
223
- _registerLetterIfMissing(87 , 53 );
224
- _registerLetterIfMissing(88 , 54 );
225
- _registerLetterIfMissing(89 , 55 );
226
- _registerLetterIfMissing(90 , 56 );
203
+ _registerLetterIfMissing(CharCode.A, KeyCode.KeyA);
204
+ _registerLetterIfMissing(CharCode.B, KeyCode.KeyB);
205
+ _registerLetterIfMissing(CharCode.C, KeyCode.KeyC);
206
+ _registerLetterIfMissing(CharCode.D, KeyCode.KeyD);
207
+ _registerLetterIfMissing(CharCode.E, KeyCode.KeyE);
208
+ _registerLetterIfMissing(CharCode.F, KeyCode.KeyF);
209
+ _registerLetterIfMissing(CharCode.G, KeyCode.KeyG);
210
+ _registerLetterIfMissing(CharCode.H, KeyCode.KeyH);
211
+ _registerLetterIfMissing(CharCode.I, KeyCode.KeyI);
212
+ _registerLetterIfMissing(CharCode.J, KeyCode.KeyJ);
213
+ _registerLetterIfMissing(CharCode.K, KeyCode.KeyK);
214
+ _registerLetterIfMissing(CharCode.L, KeyCode.KeyL);
215
+ _registerLetterIfMissing(CharCode.M, KeyCode.KeyM);
216
+ _registerLetterIfMissing(CharCode.N, KeyCode.KeyN);
217
+ _registerLetterIfMissing(CharCode.O, KeyCode.KeyO);
218
+ _registerLetterIfMissing(CharCode.P, KeyCode.KeyP);
219
+ _registerLetterIfMissing(CharCode.Q, KeyCode.KeyQ);
220
+ _registerLetterIfMissing(CharCode.R, KeyCode.KeyR);
221
+ _registerLetterIfMissing(CharCode.S, KeyCode.KeyS);
222
+ _registerLetterIfMissing(CharCode.T, KeyCode.KeyT);
223
+ _registerLetterIfMissing(CharCode.U, KeyCode.KeyU);
224
+ _registerLetterIfMissing(CharCode.V, KeyCode.KeyV);
225
+ _registerLetterIfMissing(CharCode.W, KeyCode.KeyW);
226
+ _registerLetterIfMissing(CharCode.X, KeyCode.KeyX);
227
+ _registerLetterIfMissing(CharCode.Y, KeyCode.KeyY);
228
+ _registerLetterIfMissing(CharCode.Z, KeyCode.KeyZ);
227
229
  if (!producesLetters) {
228
230
  const _registerLabel = (keyCode, charCode) => {
229
231
  this._keyCodeToLabel[keyCode] = String.fromCharCode(charCode);
230
232
  };
231
- _registerLabel(85 , 59 );
232
- _registerLabel(86 , 61 );
233
- _registerLabel(87 , 44 );
234
- _registerLabel(88 , 45 );
235
- _registerLabel(89 , 46 );
236
- _registerLabel(90 , 47 );
237
- _registerLabel(91 , 96 );
238
- _registerLabel(92 , 91 );
239
- _registerLabel(93 , 92 );
240
- _registerLabel(94 , 93 );
241
- _registerLabel(95 , 39 );
233
+ _registerLabel(KeyCode.Semicolon, CharCode.Semicolon);
234
+ _registerLabel(KeyCode.Equal, CharCode.Equals);
235
+ _registerLabel(KeyCode.Comma, CharCode.Comma);
236
+ _registerLabel(KeyCode.Minus, CharCode.Dash);
237
+ _registerLabel(KeyCode.Period, CharCode.Period);
238
+ _registerLabel(KeyCode.Slash, CharCode.Slash);
239
+ _registerLabel(KeyCode.Backquote, CharCode.BackTick);
240
+ _registerLabel(KeyCode.BracketLeft, CharCode.OpenSquareBracket);
241
+ _registerLabel(KeyCode.Backslash, CharCode.Backslash);
242
+ _registerLabel(KeyCode.BracketRight, CharCode.CloseSquareBracket);
243
+ _registerLabel(KeyCode.Quote, CharCode.SingleQuote);
242
244
  }
243
245
  }
244
246
  dumpDebugInfo() {
245
247
  const result = [];
246
248
  const immutableSamples = [
247
- 88 ,
248
- 104
249
+ ScanCode.ArrowUp,
250
+ ScanCode.Numpad0
249
251
  ];
250
252
  let cnt = 0;
251
253
  result.push(`-----------------------------------------------------------------------------------------------------------------------------------------`);
252
- for (let scanCode = 0 ; scanCode < 193 ; scanCode++) {
253
- if (IMMUTABLE_CODE_TO_KEY_CODE[scanCode] !== -1 ) {
254
+ for (let scanCode = ScanCode.None; scanCode < ScanCode.MAX_VALUE; scanCode++) {
255
+ if (IMMUTABLE_CODE_TO_KEY_CODE[scanCode] !== KeyCode.DependsOnKbLayout) {
254
256
  if (immutableSamples.indexOf(scanCode) === -1) {
255
257
  continue;
256
258
  }
@@ -310,7 +312,7 @@ class WindowsKeyboardMapper {
310
312
  return KeyCodeUtils.toElectronAccelerator(chord.keyCode);
311
313
  }
312
314
  _getLabelForKeyCode(keyCode) {
313
- return this._keyCodeToLabel[keyCode] || ( KeyCodeUtils.toString(0 ));
315
+ return this._keyCodeToLabel[keyCode] || ( KeyCodeUtils.toString(KeyCode.Unknown));
314
316
  }
315
317
  resolveKeyboardEvent(keyboardEvent) {
316
318
  const ctrlKey = keyboardEvent.ctrlKey || (this._mapAltGrToCtrlAlt && keyboardEvent.altGraphKey);
@@ -334,8 +336,8 @@ class WindowsKeyboardMapper {
334
336
  }
335
337
  return chord;
336
338
  }
337
- const keyCode = this._scanCodeToKeyCode[chord.scanCode] || 0 ;
338
- if (keyCode === 0 || !this._keyCodeExists[keyCode]) {
339
+ const keyCode = this._scanCodeToKeyCode[chord.scanCode] || KeyCode.Unknown;
340
+ if (keyCode === KeyCode.Unknown || !this._keyCodeExists[keyCode]) {
339
341
  return null;
340
342
  }
341
343
  return ( new KeyCodeChord(chord.ctrlKey, chord.shiftKey, chord.altKey, chord.metaKey, keyCode));