Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/keybinding/test/common/abstractKeybindingService.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
import assert from 'assert';
6
import { KeyChord, KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';
7
import { createSimpleKeybinding, ResolvedKeybinding, KeyCodeChord, Keybinding } from '../../../../base/common/keybindings.js';
8
import { Disposable, IDisposable } from '../../../../base/common/lifecycle.js';
9
import { OS } from '../../../../base/common/platform.js';
10
import Severity from '../../../../base/common/severity.js';
11
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
12
import { ICommandService } from '../../../commands/common/commands.js';
13
import { ContextKeyExpr, ContextKeyExpression, IContext, IContextKeyService, IContextKeyServiceTarget } from '../../../contextkey/common/contextkey.js';
14
import { AbstractKeybindingService } from '../../common/abstractKeybindingService.js';
15
import { IKeyboardEvent } from '../../common/keybinding.js';
16
import { KeybindingResolver } from '../../common/keybindingResolver.js';
17
import { ResolvedKeybindingItem } from '../../common/resolvedKeybindingItem.js';
18
import { USLayoutResolvedKeybinding } from '../../common/usLayoutResolvedKeybinding.js';
19
import { createUSLayoutResolvedKeybinding } from './keybindingsTestUtils.js';
20
import { NullLogService } from '../../../log/common/log.js';
21
import { INotification, INotificationService, IPromptChoice, IPromptOptions, IStatusMessageOptions, NoOpNotification } from '../../../notification/common/notification.js';
22
import { NullTelemetryService } from '../../../telemetry/common/telemetryUtils.js';
23
24
function createContext(ctx: any) {
25
return {
26
getValue: (key: string) => {
27
return ctx[key];
28
}
29
};
30
}
31
32
suite('AbstractKeybindingService', () => {
33
34
class TestKeybindingService extends AbstractKeybindingService {
35
private _resolver: KeybindingResolver;
36
37
constructor(
38
resolver: KeybindingResolver,
39
contextKeyService: IContextKeyService,
40
commandService: ICommandService,
41
notificationService: INotificationService
42
) {
43
super(contextKeyService, commandService, NullTelemetryService, notificationService, new NullLogService());
44
this._resolver = resolver;
45
}
46
47
protected _getResolver(): KeybindingResolver {
48
return this._resolver;
49
}
50
51
protected _documentHasFocus(): boolean {
52
return true;
53
}
54
55
public resolveKeybinding(kb: Keybinding): ResolvedKeybinding[] {
56
return USLayoutResolvedKeybinding.resolveKeybinding(kb, OS);
57
}
58
59
public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
60
const chord = new KeyCodeChord(
61
keyboardEvent.ctrlKey,
62
keyboardEvent.shiftKey,
63
keyboardEvent.altKey,
64
keyboardEvent.metaKey,
65
keyboardEvent.keyCode
66
).toKeybinding();
67
return this.resolveKeybinding(chord)[0];
68
}
69
70
public resolveUserBinding(userBinding: string): ResolvedKeybinding[] {
71
return [];
72
}
73
74
public testDispatch(kb: number): boolean {
75
const keybinding = createSimpleKeybinding(kb, OS);
76
return this._dispatch({
77
_standardKeyboardEventBrand: true,
78
ctrlKey: keybinding.ctrlKey,
79
shiftKey: keybinding.shiftKey,
80
altKey: keybinding.altKey,
81
metaKey: keybinding.metaKey,
82
altGraphKey: false,
83
keyCode: keybinding.keyCode,
84
code: null!
85
}, null!);
86
}
87
88
public _dumpDebugInfo(): string {
89
return '';
90
}
91
92
public _dumpDebugInfoJSON(): string {
93
return '';
94
}
95
96
public registerSchemaContribution(): IDisposable {
97
return Disposable.None;
98
}
99
100
public enableKeybindingHoldMode() {
101
return undefined;
102
}
103
}
104
105
let createTestKeybindingService: (items: ResolvedKeybindingItem[], contextValue?: any) => TestKeybindingService = null!;
106
let currentContextValue: IContext | null = null;
107
let executeCommandCalls: { commandId: string; args: any[] }[] = null!;
108
let showMessageCalls: { sev: Severity; message: any }[] = null!;
109
let statusMessageCalls: string[] | null = null;
110
let statusMessageCallsDisposed: string[] | null = null;
111
112
113
teardown(() => {
114
currentContextValue = null;
115
executeCommandCalls = null!;
116
showMessageCalls = null!;
117
createTestKeybindingService = null!;
118
statusMessageCalls = null;
119
statusMessageCallsDisposed = null;
120
});
121
122
ensureNoDisposablesAreLeakedInTestSuite();
123
124
setup(() => {
125
executeCommandCalls = [];
126
showMessageCalls = [];
127
statusMessageCalls = [];
128
statusMessageCallsDisposed = [];
129
130
createTestKeybindingService = (items: ResolvedKeybindingItem[]): TestKeybindingService => {
131
132
const contextKeyService: IContextKeyService = {
133
_serviceBrand: undefined,
134
onDidChangeContext: undefined!,
135
bufferChangeEvents() { },
136
createKey: undefined!,
137
contextMatchesRules: undefined!,
138
getContextKeyValue: undefined!,
139
createScoped: undefined!,
140
createOverlay: undefined!,
141
getContext: (target: IContextKeyServiceTarget): any => {
142
return currentContextValue;
143
},
144
updateParent: () => { }
145
};
146
147
const commandService: ICommandService = {
148
_serviceBrand: undefined,
149
onWillExecuteCommand: () => Disposable.None,
150
onDidExecuteCommand: () => Disposable.None,
151
executeCommand: (commandId: string, ...args: any[]): Promise<any> => {
152
executeCommandCalls.push({
153
commandId: commandId,
154
args: args
155
});
156
return Promise.resolve(undefined);
157
}
158
};
159
160
const notificationService: INotificationService = {
161
_serviceBrand: undefined,
162
onDidChangeFilter: undefined!,
163
notify: (notification: INotification) => {
164
showMessageCalls.push({ sev: notification.severity, message: notification.message });
165
return new NoOpNotification();
166
},
167
info: (message: any) => {
168
showMessageCalls.push({ sev: Severity.Info, message });
169
return new NoOpNotification();
170
},
171
warn: (message: any) => {
172
showMessageCalls.push({ sev: Severity.Warning, message });
173
return new NoOpNotification();
174
},
175
error: (message: any) => {
176
showMessageCalls.push({ sev: Severity.Error, message });
177
return new NoOpNotification();
178
},
179
prompt(severity: Severity, message: string, choices: IPromptChoice[], options?: IPromptOptions) {
180
throw new Error('not implemented');
181
},
182
status(message: string, options?: IStatusMessageOptions) {
183
statusMessageCalls!.push(message);
184
return {
185
close: () => {
186
statusMessageCallsDisposed!.push(message);
187
}
188
};
189
},
190
setFilter() {
191
throw new Error('not implemented');
192
},
193
getFilter() {
194
throw new Error('not implemented');
195
},
196
getFilters() {
197
throw new Error('not implemented');
198
},
199
removeFilter() {
200
throw new Error('not implemented');
201
}
202
};
203
204
const resolver = new KeybindingResolver(items, [], () => { });
205
206
return new TestKeybindingService(resolver, contextKeyService, commandService, notificationService);
207
};
208
});
209
210
function kbItem(keybinding: number | number[], command: string | null, when?: ContextKeyExpression): ResolvedKeybindingItem {
211
return new ResolvedKeybindingItem(
212
createUSLayoutResolvedKeybinding(keybinding, OS),
213
command,
214
null,
215
when,
216
true,
217
null,
218
false
219
);
220
}
221
222
function toUsLabel(keybinding: number): string {
223
return createUSLayoutResolvedKeybinding(keybinding, OS)!.getLabel()!;
224
}
225
226
suite('simple tests: single- and multi-chord keybindings are dispatched', () => {
227
228
test('a single-chord keybinding is dispatched correctly; this test makes sure the dispatch in general works before we test empty-string/null command ID', () => {
229
230
const key = KeyMod.CtrlCmd | KeyCode.KeyK;
231
const kbService = createTestKeybindingService([
232
kbItem(key, 'myCommand'),
233
]);
234
235
currentContextValue = createContext({});
236
const shouldPreventDefault = kbService.testDispatch(key);
237
assert.deepStrictEqual(shouldPreventDefault, true);
238
assert.deepStrictEqual(executeCommandCalls, ([{ commandId: "myCommand", args: [null] }]));
239
assert.deepStrictEqual(showMessageCalls, []);
240
assert.deepStrictEqual(statusMessageCalls, []);
241
assert.deepStrictEqual(statusMessageCallsDisposed, []);
242
243
kbService.dispose();
244
});
245
246
test('a multi-chord keybinding is dispatched correctly', () => {
247
248
const chord0 = KeyMod.CtrlCmd | KeyCode.KeyK;
249
const chord1 = KeyMod.CtrlCmd | KeyCode.KeyI;
250
const key = [chord0, chord1];
251
const kbService = createTestKeybindingService([
252
kbItem(key, 'myCommand'),
253
]);
254
255
currentContextValue = createContext({});
256
257
let shouldPreventDefault = kbService.testDispatch(chord0);
258
assert.deepStrictEqual(shouldPreventDefault, true);
259
assert.deepStrictEqual(executeCommandCalls, []);
260
assert.deepStrictEqual(showMessageCalls, []);
261
assert.deepStrictEqual(statusMessageCalls, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`]));
262
assert.deepStrictEqual(statusMessageCallsDisposed, []);
263
264
shouldPreventDefault = kbService.testDispatch(chord1);
265
assert.deepStrictEqual(shouldPreventDefault, true);
266
assert.deepStrictEqual(executeCommandCalls, ([{ commandId: "myCommand", args: [null] }]));
267
assert.deepStrictEqual(showMessageCalls, []);
268
assert.deepStrictEqual(statusMessageCalls, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`]));
269
assert.deepStrictEqual(statusMessageCallsDisposed, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`]));
270
271
kbService.dispose();
272
});
273
});
274
275
suite('keybindings with empty-string/null command ID', () => {
276
277
test('a single-chord keybinding with an empty string command ID unbinds the keybinding (shouldPreventDefault = false)', () => {
278
279
const kbService = createTestKeybindingService([
280
kbItem(KeyMod.CtrlCmd | KeyCode.KeyK, 'myCommand'),
281
kbItem(KeyMod.CtrlCmd | KeyCode.KeyK, ''),
282
]);
283
284
// send Ctrl/Cmd + K
285
currentContextValue = createContext({});
286
const shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
287
assert.deepStrictEqual(shouldPreventDefault, false);
288
assert.deepStrictEqual(executeCommandCalls, []);
289
assert.deepStrictEqual(showMessageCalls, []);
290
assert.deepStrictEqual(statusMessageCalls, []);
291
assert.deepStrictEqual(statusMessageCallsDisposed, []);
292
293
kbService.dispose();
294
});
295
296
test('a single-chord keybinding with a null command ID unbinds the keybinding (shouldPreventDefault = false)', () => {
297
298
const kbService = createTestKeybindingService([
299
kbItem(KeyMod.CtrlCmd | KeyCode.KeyK, 'myCommand'),
300
kbItem(KeyMod.CtrlCmd | KeyCode.KeyK, null),
301
]);
302
303
// send Ctrl/Cmd + K
304
currentContextValue = createContext({});
305
const shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
306
assert.deepStrictEqual(shouldPreventDefault, false);
307
assert.deepStrictEqual(executeCommandCalls, []);
308
assert.deepStrictEqual(showMessageCalls, []);
309
assert.deepStrictEqual(statusMessageCalls, []);
310
assert.deepStrictEqual(statusMessageCallsDisposed, []);
311
312
kbService.dispose();
313
});
314
315
test('a multi-chord keybinding with an empty-string command ID keeps the keybinding (shouldPreventDefault = true)', () => {
316
317
const chord0 = KeyMod.CtrlCmd | KeyCode.KeyK;
318
const chord1 = KeyMod.CtrlCmd | KeyCode.KeyI;
319
const key = [chord0, chord1];
320
const kbService = createTestKeybindingService([
321
kbItem(key, 'myCommand'),
322
kbItem(key, ''),
323
]);
324
325
currentContextValue = createContext({});
326
327
let shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
328
assert.deepStrictEqual(shouldPreventDefault, true);
329
assert.deepStrictEqual(executeCommandCalls, []);
330
assert.deepStrictEqual(showMessageCalls, []);
331
assert.deepStrictEqual(statusMessageCalls, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`]));
332
assert.deepStrictEqual(statusMessageCallsDisposed, []);
333
334
shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyI);
335
assert.deepStrictEqual(shouldPreventDefault, true);
336
assert.deepStrictEqual(executeCommandCalls, []);
337
assert.deepStrictEqual(showMessageCalls, []);
338
assert.deepStrictEqual(statusMessageCalls, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`, `The key combination (${toUsLabel(chord0)}, ${toUsLabel(chord1)}) is not a command.`]));
339
assert.deepStrictEqual(statusMessageCallsDisposed, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`]));
340
341
kbService.dispose();
342
});
343
344
test('a multi-chord keybinding with a null command ID keeps the keybinding (shouldPreventDefault = true)', () => {
345
346
const chord0 = KeyMod.CtrlCmd | KeyCode.KeyK;
347
const chord1 = KeyMod.CtrlCmd | KeyCode.KeyI;
348
const key = [chord0, chord1];
349
const kbService = createTestKeybindingService([
350
kbItem(key, 'myCommand'),
351
kbItem(key, null),
352
]);
353
354
currentContextValue = createContext({});
355
356
let shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
357
assert.deepStrictEqual(shouldPreventDefault, true);
358
assert.deepStrictEqual(executeCommandCalls, []);
359
assert.deepStrictEqual(showMessageCalls, []);
360
assert.deepStrictEqual(statusMessageCalls, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`]));
361
assert.deepStrictEqual(statusMessageCallsDisposed, []);
362
363
shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyI);
364
assert.deepStrictEqual(shouldPreventDefault, true);
365
assert.deepStrictEqual(executeCommandCalls, []);
366
assert.deepStrictEqual(showMessageCalls, []);
367
assert.deepStrictEqual(statusMessageCalls, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`, `The key combination (${toUsLabel(chord0)}, ${toUsLabel(chord1)}) is not a command.`]));
368
assert.deepStrictEqual(statusMessageCallsDisposed, ([`(${toUsLabel(chord0)}) was pressed. Waiting for second key of chord...`]));
369
370
kbService.dispose();
371
});
372
373
});
374
375
test('issue #16498: chord mode is quit for invalid chords', () => {
376
377
const kbService = createTestKeybindingService([
378
kbItem(KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyX), 'chordCommand'),
379
kbItem(KeyCode.Backspace, 'simpleCommand'),
380
]);
381
382
// send Ctrl/Cmd + K
383
let shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
384
assert.strictEqual(shouldPreventDefault, true);
385
assert.deepStrictEqual(executeCommandCalls, []);
386
assert.deepStrictEqual(showMessageCalls, []);
387
assert.deepStrictEqual(statusMessageCalls, [
388
`(${toUsLabel(KeyMod.CtrlCmd | KeyCode.KeyK)}) was pressed. Waiting for second key of chord...`
389
]);
390
assert.deepStrictEqual(statusMessageCallsDisposed, []);
391
executeCommandCalls = [];
392
showMessageCalls = [];
393
statusMessageCalls = [];
394
statusMessageCallsDisposed = [];
395
396
// send backspace
397
shouldPreventDefault = kbService.testDispatch(KeyCode.Backspace);
398
assert.strictEqual(shouldPreventDefault, true);
399
assert.deepStrictEqual(executeCommandCalls, []);
400
assert.deepStrictEqual(showMessageCalls, []);
401
assert.deepStrictEqual(statusMessageCalls, [
402
`The key combination (${toUsLabel(KeyMod.CtrlCmd | KeyCode.KeyK)}, ${toUsLabel(KeyCode.Backspace)}) is not a command.`
403
]);
404
assert.deepStrictEqual(statusMessageCallsDisposed, [
405
`(${toUsLabel(KeyMod.CtrlCmd | KeyCode.KeyK)}) was pressed. Waiting for second key of chord...`
406
]);
407
executeCommandCalls = [];
408
showMessageCalls = [];
409
statusMessageCalls = [];
410
statusMessageCallsDisposed = [];
411
412
// send backspace
413
shouldPreventDefault = kbService.testDispatch(KeyCode.Backspace);
414
assert.strictEqual(shouldPreventDefault, true);
415
assert.deepStrictEqual(executeCommandCalls, [{
416
commandId: 'simpleCommand',
417
args: [null]
418
}]);
419
assert.deepStrictEqual(showMessageCalls, []);
420
assert.deepStrictEqual(statusMessageCalls, []);
421
assert.deepStrictEqual(statusMessageCallsDisposed, []);
422
executeCommandCalls = [];
423
showMessageCalls = [];
424
statusMessageCalls = [];
425
statusMessageCallsDisposed = [];
426
427
kbService.dispose();
428
});
429
430
test('issue #16833: Keybinding service should not testDispatch on modifier keys', () => {
431
432
const kbService = createTestKeybindingService([
433
kbItem(KeyCode.Ctrl, 'nope'),
434
kbItem(KeyCode.Meta, 'nope'),
435
kbItem(KeyCode.Alt, 'nope'),
436
kbItem(KeyCode.Shift, 'nope'),
437
438
kbItem(KeyMod.CtrlCmd, 'nope'),
439
kbItem(KeyMod.WinCtrl, 'nope'),
440
kbItem(KeyMod.Alt, 'nope'),
441
kbItem(KeyMod.Shift, 'nope'),
442
]);
443
444
function assertIsIgnored(keybinding: number): void {
445
const shouldPreventDefault = kbService.testDispatch(keybinding);
446
assert.strictEqual(shouldPreventDefault, false);
447
assert.deepStrictEqual(executeCommandCalls, []);
448
assert.deepStrictEqual(showMessageCalls, []);
449
assert.deepStrictEqual(statusMessageCalls, []);
450
assert.deepStrictEqual(statusMessageCallsDisposed, []);
451
executeCommandCalls = [];
452
showMessageCalls = [];
453
statusMessageCalls = [];
454
statusMessageCallsDisposed = [];
455
}
456
457
assertIsIgnored(KeyCode.Ctrl);
458
assertIsIgnored(KeyCode.Meta);
459
assertIsIgnored(KeyCode.Alt);
460
assertIsIgnored(KeyCode.Shift);
461
462
assertIsIgnored(KeyMod.CtrlCmd);
463
assertIsIgnored(KeyMod.WinCtrl);
464
assertIsIgnored(KeyMod.Alt);
465
assertIsIgnored(KeyMod.Shift);
466
467
kbService.dispose();
468
});
469
470
test('can trigger command that is sharing keybinding with chord', () => {
471
472
const kbService = createTestKeybindingService([
473
kbItem(KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyX), 'chordCommand'),
474
kbItem(KeyMod.CtrlCmd | KeyCode.KeyK, 'simpleCommand', ContextKeyExpr.has('key1')),
475
]);
476
477
478
// send Ctrl/Cmd + K
479
currentContextValue = createContext({
480
key1: true
481
});
482
let shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
483
assert.strictEqual(shouldPreventDefault, true);
484
assert.deepStrictEqual(executeCommandCalls, [{
485
commandId: 'simpleCommand',
486
args: [null]
487
}]);
488
assert.deepStrictEqual(showMessageCalls, []);
489
assert.deepStrictEqual(statusMessageCalls, []);
490
assert.deepStrictEqual(statusMessageCallsDisposed, []);
491
executeCommandCalls = [];
492
showMessageCalls = [];
493
statusMessageCalls = [];
494
statusMessageCallsDisposed = [];
495
496
// send Ctrl/Cmd + K
497
currentContextValue = createContext({});
498
shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
499
assert.strictEqual(shouldPreventDefault, true);
500
assert.deepStrictEqual(executeCommandCalls, []);
501
assert.deepStrictEqual(showMessageCalls, []);
502
assert.deepStrictEqual(statusMessageCalls, [
503
`(${toUsLabel(KeyMod.CtrlCmd | KeyCode.KeyK)}) was pressed. Waiting for second key of chord...`
504
]);
505
assert.deepStrictEqual(statusMessageCallsDisposed, []);
506
executeCommandCalls = [];
507
showMessageCalls = [];
508
statusMessageCalls = [];
509
statusMessageCallsDisposed = [];
510
511
// send Ctrl/Cmd + X
512
currentContextValue = createContext({});
513
shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyX);
514
assert.strictEqual(shouldPreventDefault, true);
515
assert.deepStrictEqual(executeCommandCalls, [{
516
commandId: 'chordCommand',
517
args: [null]
518
}]);
519
assert.deepStrictEqual(showMessageCalls, []);
520
assert.deepStrictEqual(statusMessageCalls, []);
521
assert.deepStrictEqual(statusMessageCallsDisposed, [
522
`(${toUsLabel(KeyMod.CtrlCmd | KeyCode.KeyK)}) was pressed. Waiting for second key of chord...`
523
]);
524
executeCommandCalls = [];
525
showMessageCalls = [];
526
statusMessageCalls = [];
527
statusMessageCallsDisposed = [];
528
529
kbService.dispose();
530
});
531
532
test('cannot trigger chord if command is overwriting', () => {
533
534
const kbService = createTestKeybindingService([
535
kbItem(KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyX), 'chordCommand', ContextKeyExpr.has('key1')),
536
kbItem(KeyMod.CtrlCmd | KeyCode.KeyK, 'simpleCommand'),
537
]);
538
539
540
// send Ctrl/Cmd + K
541
currentContextValue = createContext({});
542
let shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
543
assert.strictEqual(shouldPreventDefault, true);
544
assert.deepStrictEqual(executeCommandCalls, [{
545
commandId: 'simpleCommand',
546
args: [null]
547
}]);
548
assert.deepStrictEqual(showMessageCalls, []);
549
assert.deepStrictEqual(statusMessageCalls, []);
550
assert.deepStrictEqual(statusMessageCallsDisposed, []);
551
executeCommandCalls = [];
552
showMessageCalls = [];
553
statusMessageCalls = [];
554
statusMessageCallsDisposed = [];
555
556
// send Ctrl/Cmd + K
557
currentContextValue = createContext({
558
key1: true
559
});
560
shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
561
assert.strictEqual(shouldPreventDefault, true);
562
assert.deepStrictEqual(executeCommandCalls, [{
563
commandId: 'simpleCommand',
564
args: [null]
565
}]);
566
assert.deepStrictEqual(showMessageCalls, []);
567
assert.deepStrictEqual(statusMessageCalls, []);
568
assert.deepStrictEqual(statusMessageCallsDisposed, []);
569
executeCommandCalls = [];
570
showMessageCalls = [];
571
statusMessageCalls = [];
572
statusMessageCallsDisposed = [];
573
574
// send Ctrl/Cmd + X
575
currentContextValue = createContext({
576
key1: true
577
});
578
shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyX);
579
assert.strictEqual(shouldPreventDefault, false);
580
assert.deepStrictEqual(executeCommandCalls, []);
581
assert.deepStrictEqual(showMessageCalls, []);
582
assert.deepStrictEqual(statusMessageCalls, []);
583
assert.deepStrictEqual(statusMessageCallsDisposed, []);
584
executeCommandCalls = [];
585
showMessageCalls = [];
586
statusMessageCalls = [];
587
statusMessageCallsDisposed = [];
588
589
kbService.dispose();
590
});
591
592
test('can have spying command', () => {
593
594
const kbService = createTestKeybindingService([
595
kbItem(KeyMod.CtrlCmd | KeyCode.KeyK, '^simpleCommand'),
596
]);
597
598
// send Ctrl/Cmd + K
599
currentContextValue = createContext({});
600
const shouldPreventDefault = kbService.testDispatch(KeyMod.CtrlCmd | KeyCode.KeyK);
601
assert.strictEqual(shouldPreventDefault, false);
602
assert.deepStrictEqual(executeCommandCalls, [{
603
commandId: 'simpleCommand',
604
args: [null]
605
}]);
606
assert.deepStrictEqual(showMessageCalls, []);
607
assert.deepStrictEqual(statusMessageCalls, []);
608
assert.deepStrictEqual(statusMessageCallsDisposed, []);
609
executeCommandCalls = [];
610
showMessageCalls = [];
611
statusMessageCalls = [];
612
statusMessageCallsDisposed = [];
613
614
kbService.dispose();
615
});
616
});
617
618