Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/keybinding/test/node/fallbackKeyboardMapper.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { KeyChord, KeyCode, KeyMod, ScanCode } from '../../../../../base/common/keyCodes.js';
7
import { KeyCodeChord, decodeKeybinding, ScanCodeChord, Keybinding } from '../../../../../base/common/keybindings.js';
8
import { OperatingSystem } from '../../../../../base/common/platform.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
10
import { FallbackKeyboardMapper } from '../../common/fallbackKeyboardMapper.js';
11
import { IResolvedKeybinding, assertResolveKeyboardEvent, assertResolveKeybinding } from './keyboardMapperTestUtils.js';
12
13
suite('keyboardMapper - MAC fallback', () => {
14
15
ensureNoDisposablesAreLeakedInTestSuite();
16
17
const mapper = new FallbackKeyboardMapper(false, OperatingSystem.Macintosh);
18
19
function _assertResolveKeybinding(k: number, expected: IResolvedKeybinding[]): void {
20
assertResolveKeybinding(mapper, decodeKeybinding(k, OperatingSystem.Macintosh)!, expected);
21
}
22
23
test('resolveKeybinding Cmd+Z', () => {
24
_assertResolveKeybinding(
25
KeyMod.CtrlCmd | KeyCode.KeyZ,
26
[{
27
label: '⌘Z',
28
ariaLabel: 'Command+Z',
29
electronAccelerator: 'Cmd+Z',
30
userSettingsLabel: 'cmd+z',
31
isWYSIWYG: true,
32
isMultiChord: false,
33
dispatchParts: ['meta+Z'],
34
singleModifierDispatchParts: [null],
35
}]
36
);
37
});
38
39
test('resolveKeybinding Cmd+K Cmd+=', () => {
40
_assertResolveKeybinding(
41
KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.Equal),
42
[{
43
label: '⌘K ⌘=',
44
ariaLabel: 'Command+K Command+=',
45
electronAccelerator: null,
46
userSettingsLabel: 'cmd+k cmd+=',
47
isWYSIWYG: true,
48
isMultiChord: true,
49
dispatchParts: ['meta+K', 'meta+='],
50
singleModifierDispatchParts: [null, null],
51
}]
52
);
53
});
54
55
test('resolveKeyboardEvent Cmd+Z', () => {
56
assertResolveKeyboardEvent(
57
mapper,
58
{
59
_standardKeyboardEventBrand: true,
60
ctrlKey: false,
61
shiftKey: false,
62
altKey: false,
63
metaKey: true,
64
altGraphKey: false,
65
keyCode: KeyCode.KeyZ,
66
code: null!
67
},
68
{
69
label: '⌘Z',
70
ariaLabel: 'Command+Z',
71
electronAccelerator: 'Cmd+Z',
72
userSettingsLabel: 'cmd+z',
73
isWYSIWYG: true,
74
isMultiChord: false,
75
dispatchParts: ['meta+Z'],
76
singleModifierDispatchParts: [null],
77
}
78
);
79
});
80
81
test('resolveUserBinding Cmd+[Comma] Cmd+/', () => {
82
assertResolveKeybinding(
83
mapper, new Keybinding([
84
new ScanCodeChord(false, false, false, true, ScanCode.Comma),
85
new KeyCodeChord(false, false, false, true, KeyCode.Slash),
86
]),
87
[{
88
label: '⌘, ⌘/',
89
ariaLabel: 'Command+, Command+/',
90
electronAccelerator: null,
91
userSettingsLabel: 'cmd+, cmd+/',
92
isWYSIWYG: true,
93
isMultiChord: true,
94
dispatchParts: ['meta+,', 'meta+/'],
95
singleModifierDispatchParts: [null, null],
96
}]
97
);
98
});
99
100
test('resolveKeyboardEvent Single Modifier Meta+', () => {
101
assertResolveKeyboardEvent(
102
mapper,
103
{
104
_standardKeyboardEventBrand: true,
105
ctrlKey: false,
106
shiftKey: false,
107
altKey: false,
108
metaKey: true,
109
altGraphKey: false,
110
keyCode: KeyCode.Meta,
111
code: null!
112
},
113
{
114
label: '⌘',
115
ariaLabel: 'Command',
116
electronAccelerator: null,
117
userSettingsLabel: 'cmd',
118
isWYSIWYG: true,
119
isMultiChord: false,
120
dispatchParts: [null],
121
singleModifierDispatchParts: ['meta'],
122
}
123
);
124
});
125
126
test('resolveKeyboardEvent Single Modifier Shift+', () => {
127
assertResolveKeyboardEvent(
128
mapper,
129
{
130
_standardKeyboardEventBrand: true,
131
ctrlKey: false,
132
shiftKey: true,
133
altKey: false,
134
metaKey: false,
135
altGraphKey: false,
136
keyCode: KeyCode.Shift,
137
code: null!
138
},
139
{
140
label: '⇧',
141
ariaLabel: 'Shift',
142
electronAccelerator: null,
143
userSettingsLabel: 'shift',
144
isWYSIWYG: true,
145
isMultiChord: false,
146
dispatchParts: [null],
147
singleModifierDispatchParts: ['shift'],
148
}
149
);
150
});
151
152
test('resolveKeyboardEvent Single Modifier Alt+', () => {
153
assertResolveKeyboardEvent(
154
mapper,
155
{
156
_standardKeyboardEventBrand: true,
157
ctrlKey: false,
158
shiftKey: false,
159
altKey: true,
160
metaKey: false,
161
altGraphKey: false,
162
keyCode: KeyCode.Alt,
163
code: null!
164
},
165
{
166
label: '⌥',
167
ariaLabel: 'Option',
168
electronAccelerator: null,
169
userSettingsLabel: 'alt',
170
isWYSIWYG: true,
171
isMultiChord: false,
172
dispatchParts: [null],
173
singleModifierDispatchParts: ['alt'],
174
}
175
);
176
});
177
178
test('resolveKeyboardEvent Only Modifiers Ctrl+Shift+', () => {
179
assertResolveKeyboardEvent(
180
mapper,
181
{
182
_standardKeyboardEventBrand: true,
183
ctrlKey: true,
184
shiftKey: true,
185
altKey: false,
186
metaKey: false,
187
altGraphKey: false,
188
keyCode: KeyCode.Shift,
189
code: null!
190
},
191
{
192
label: '⌃⇧',
193
ariaLabel: 'Control+Shift',
194
electronAccelerator: null,
195
userSettingsLabel: 'ctrl+shift',
196
isWYSIWYG: true,
197
isMultiChord: false,
198
dispatchParts: [null],
199
singleModifierDispatchParts: [null],
200
}
201
);
202
});
203
204
test('resolveKeyboardEvent mapAltGrToCtrlAlt AltGr+Z', () => {
205
const mapper = new FallbackKeyboardMapper(true, OperatingSystem.Macintosh);
206
207
assertResolveKeyboardEvent(
208
mapper,
209
{
210
_standardKeyboardEventBrand: true,
211
ctrlKey: false,
212
shiftKey: false,
213
altKey: false,
214
metaKey: false,
215
altGraphKey: true,
216
keyCode: KeyCode.KeyZ,
217
code: null!
218
},
219
{
220
label: '⌃⌥Z',
221
ariaLabel: 'Control+Option+Z',
222
electronAccelerator: 'Ctrl+Alt+Z',
223
userSettingsLabel: 'ctrl+alt+z',
224
isWYSIWYG: true,
225
isMultiChord: false,
226
dispatchParts: ['ctrl+alt+Z'],
227
singleModifierDispatchParts: [null],
228
}
229
);
230
});
231
});
232
233
suite('keyboardMapper - LINUX fallback', () => {
234
235
ensureNoDisposablesAreLeakedInTestSuite();
236
237
const mapper = new FallbackKeyboardMapper(false, OperatingSystem.Linux);
238
239
function _assertResolveKeybinding(k: number, expected: IResolvedKeybinding[]): void {
240
assertResolveKeybinding(mapper, decodeKeybinding(k, OperatingSystem.Linux)!, expected);
241
}
242
243
test('resolveKeybinding Ctrl+Z', () => {
244
_assertResolveKeybinding(
245
KeyMod.CtrlCmd | KeyCode.KeyZ,
246
[{
247
label: 'Ctrl+Z',
248
ariaLabel: 'Control+Z',
249
electronAccelerator: 'Ctrl+Z',
250
userSettingsLabel: 'ctrl+z',
251
isWYSIWYG: true,
252
isMultiChord: false,
253
dispatchParts: ['ctrl+Z'],
254
singleModifierDispatchParts: [null],
255
}]
256
);
257
});
258
259
test('resolveKeybinding Ctrl+K Ctrl+=', () => {
260
_assertResolveKeybinding(
261
KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.Equal),
262
[{
263
label: 'Ctrl+K Ctrl+=',
264
ariaLabel: 'Control+K Control+=',
265
electronAccelerator: null,
266
userSettingsLabel: 'ctrl+k ctrl+=',
267
isWYSIWYG: true,
268
isMultiChord: true,
269
dispatchParts: ['ctrl+K', 'ctrl+='],
270
singleModifierDispatchParts: [null, null],
271
}]
272
);
273
});
274
275
test('resolveKeyboardEvent Ctrl+Z', () => {
276
assertResolveKeyboardEvent(
277
mapper,
278
{
279
_standardKeyboardEventBrand: true,
280
ctrlKey: true,
281
shiftKey: false,
282
altKey: false,
283
metaKey: false,
284
altGraphKey: false,
285
keyCode: KeyCode.KeyZ,
286
code: null!
287
},
288
{
289
label: 'Ctrl+Z',
290
ariaLabel: 'Control+Z',
291
electronAccelerator: 'Ctrl+Z',
292
userSettingsLabel: 'ctrl+z',
293
isWYSIWYG: true,
294
isMultiChord: false,
295
dispatchParts: ['ctrl+Z'],
296
singleModifierDispatchParts: [null],
297
}
298
);
299
});
300
301
test('resolveUserBinding Ctrl+[Comma] Ctrl+/', () => {
302
assertResolveKeybinding(
303
mapper, new Keybinding([
304
new ScanCodeChord(true, false, false, false, ScanCode.Comma),
305
new KeyCodeChord(true, false, false, false, KeyCode.Slash),
306
]),
307
[{
308
label: 'Ctrl+, Ctrl+/',
309
ariaLabel: 'Control+, Control+/',
310
electronAccelerator: null,
311
userSettingsLabel: 'ctrl+, ctrl+/',
312
isWYSIWYG: true,
313
isMultiChord: true,
314
dispatchParts: ['ctrl+,', 'ctrl+/'],
315
singleModifierDispatchParts: [null, null],
316
}]
317
);
318
});
319
320
test('resolveUserBinding Ctrl+[Comma]', () => {
321
assertResolveKeybinding(
322
mapper, new Keybinding([
323
new ScanCodeChord(true, false, false, false, ScanCode.Comma),
324
]),
325
[{
326
label: 'Ctrl+,',
327
ariaLabel: 'Control+,',
328
electronAccelerator: 'Ctrl+,',
329
userSettingsLabel: 'ctrl+,',
330
isWYSIWYG: true,
331
isMultiChord: false,
332
dispatchParts: ['ctrl+,'],
333
singleModifierDispatchParts: [null],
334
}]
335
);
336
});
337
338
test('resolveKeyboardEvent Single Modifier Ctrl+', () => {
339
assertResolveKeyboardEvent(
340
mapper,
341
{
342
_standardKeyboardEventBrand: true,
343
ctrlKey: true,
344
shiftKey: false,
345
altKey: false,
346
metaKey: false,
347
altGraphKey: false,
348
keyCode: KeyCode.Ctrl,
349
code: null!
350
},
351
{
352
label: 'Ctrl',
353
ariaLabel: 'Control',
354
electronAccelerator: null,
355
userSettingsLabel: 'ctrl',
356
isWYSIWYG: true,
357
isMultiChord: false,
358
dispatchParts: [null],
359
singleModifierDispatchParts: ['ctrl'],
360
}
361
);
362
});
363
364
test('resolveKeyboardEvent mapAltGrToCtrlAlt AltGr+Z', () => {
365
const mapper = new FallbackKeyboardMapper(true, OperatingSystem.Linux);
366
367
assertResolveKeyboardEvent(
368
mapper,
369
{
370
_standardKeyboardEventBrand: true,
371
ctrlKey: false,
372
shiftKey: false,
373
altKey: false,
374
metaKey: false,
375
altGraphKey: true,
376
keyCode: KeyCode.KeyZ,
377
code: null!
378
},
379
{
380
label: 'Ctrl+Alt+Z',
381
ariaLabel: 'Control+Alt+Z',
382
electronAccelerator: 'Ctrl+Alt+Z',
383
userSettingsLabel: 'ctrl+alt+z',
384
isWYSIWYG: true,
385
isMultiChord: false,
386
dispatchParts: ['ctrl+alt+Z'],
387
singleModifierDispatchParts: [null],
388
}
389
);
390
});
391
});
392
393