Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/standalone/test/browser/standaloneServices.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 assert from 'assert';
7
import { KeyCode } from '../../../../base/common/keyCodes.js';
8
import { DisposableStore } from '../../../../base/common/lifecycle.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
10
import { StandaloneCodeEditorService } from '../../browser/standaloneCodeEditorService.js';
11
import { StandaloneCommandService, StandaloneConfigurationService, StandaloneKeybindingService, StandaloneNotificationService } from '../../browser/standaloneServices.js';
12
import { StandaloneThemeService } from '../../browser/standaloneThemeService.js';
13
import { ContextKeyService } from '../../../../platform/contextkey/browser/contextKeyService.js';
14
import { InstantiationService } from '../../../../platform/instantiation/common/instantiationService.js';
15
import { ServiceCollection } from '../../../../platform/instantiation/common/serviceCollection.js';
16
import { IKeyboardEvent } from '../../../../platform/keybinding/common/keybinding.js';
17
import { NullLogService } from '../../../../platform/log/common/log.js';
18
import { NullTelemetryService } from '../../../../platform/telemetry/common/telemetryUtils.js';
19
20
suite('StandaloneKeybindingService', () => {
21
22
ensureNoDisposablesAreLeakedInTestSuite();
23
24
class TestStandaloneKeybindingService extends StandaloneKeybindingService {
25
public testDispatch(e: IKeyboardEvent): void {
26
super._dispatch(e, null!);
27
}
28
}
29
30
test('issue microsoft/monaco-editor#167', () => {
31
32
const disposables = new DisposableStore();
33
const serviceCollection = new ServiceCollection();
34
const instantiationService = new InstantiationService(serviceCollection, true);
35
const configurationService = new StandaloneConfigurationService(new NullLogService());
36
const contextKeyService = disposables.add(new ContextKeyService(configurationService));
37
const commandService = new StandaloneCommandService(instantiationService);
38
const notificationService = new StandaloneNotificationService();
39
const standaloneThemeService = disposables.add(new StandaloneThemeService());
40
const codeEditorService = disposables.add(new StandaloneCodeEditorService(contextKeyService, standaloneThemeService));
41
const keybindingService = disposables.add(new TestStandaloneKeybindingService(contextKeyService, commandService, NullTelemetryService, notificationService, new NullLogService(), codeEditorService));
42
43
let commandInvoked = false;
44
disposables.add(keybindingService.addDynamicKeybinding('testCommand', KeyCode.F9, () => {
45
commandInvoked = true;
46
}, undefined));
47
48
keybindingService.testDispatch({
49
_standardKeyboardEventBrand: true,
50
ctrlKey: false,
51
shiftKey: false,
52
altKey: false,
53
metaKey: false,
54
altGraphKey: false,
55
keyCode: KeyCode.F9,
56
code: null!
57
});
58
59
assert.ok(commandInvoked, 'command invoked');
60
61
disposables.dispose();
62
});
63
});
64
65