Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/keybinding/test/browser/browserKeyboardMapper.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 '../../browser/keyboardLayouts/en.darwin.js';
7
import '../../browser/keyboardLayouts/de.darwin.js';
8
import { KeyboardLayoutContribution } from '../../browser/keyboardLayouts/_.contribution.js';
9
import { BrowserKeyboardMapperFactoryBase } from '../../browser/keyboardLayoutService.js';
10
import { KeymapInfo, IKeymapInfo } from '../../common/keymapInfo.js';
11
import { TestInstantiationService } from '../../../../../platform/instantiation/test/common/instantiationServiceMock.js';
12
import { INotificationService } from '../../../../../platform/notification/common/notification.js';
13
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
14
import { IStorageService } from '../../../../../platform/storage/common/storage.js';
15
import { TestNotificationService } from '../../../../../platform/notification/test/common/testNotificationService.js';
16
import { TestStorageService } from '../../../../test/common/workbenchTestServices.js';
17
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
18
import { TestConfigurationService } from '../../../../../platform/configuration/test/common/testConfigurationService.js';
19
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
20
21
class TestKeyboardMapperFactory extends BrowserKeyboardMapperFactoryBase {
22
constructor(configurationService: IConfigurationService, notificationService: INotificationService, storageService: IStorageService, commandService: ICommandService) {
23
// super(notificationService, storageService, commandService);
24
super(configurationService);
25
26
const keymapInfos: IKeymapInfo[] = KeyboardLayoutContribution.INSTANCE.layoutInfos;
27
this._keymapInfos.push(...keymapInfos.map(info => (new KeymapInfo(info.layout, info.secondaryLayouts, info.mapping, info.isUserKeyboardLayout))));
28
this._mru = this._keymapInfos;
29
this._initialized = true;
30
this.setLayoutFromBrowserAPI();
31
const usLayout = this.getUSStandardLayout();
32
if (usLayout) {
33
this.setActiveKeyMapping(usLayout.mapping);
34
}
35
}
36
}
37
38
suite('keyboard layout loader', () => {
39
const ds = ensureNoDisposablesAreLeakedInTestSuite();
40
let instantiationService: TestInstantiationService;
41
let instance: TestKeyboardMapperFactory;
42
43
setup(() => {
44
instantiationService = new TestInstantiationService();
45
const storageService = new TestStorageService();
46
const notitifcationService = instantiationService.stub(INotificationService, new TestNotificationService());
47
const configurationService = instantiationService.stub(IConfigurationService, new TestConfigurationService());
48
const commandService = instantiationService.stub(ICommandService, {});
49
50
ds.add(instantiationService);
51
ds.add(storageService);
52
53
instance = new TestKeyboardMapperFactory(configurationService, notitifcationService, storageService, commandService);
54
ds.add(instance);
55
});
56
57
teardown(() => {
58
instantiationService.dispose();
59
});
60
61
test('load default US keyboard layout', () => {
62
assert.notStrictEqual(instance.activeKeyboardLayout, null);
63
});
64
65
test('isKeyMappingActive', () => {
66
instance.setUSKeyboardLayout();
67
assert.strictEqual(instance.isKeyMappingActive({
68
KeyA: {
69
value: 'a',
70
valueIsDeadKey: false,
71
withShift: 'A',
72
withShiftIsDeadKey: false,
73
withAltGr: 'å',
74
withAltGrIsDeadKey: false,
75
withShiftAltGr: 'Å',
76
withShiftAltGrIsDeadKey: false
77
}
78
}), true);
79
80
assert.strictEqual(instance.isKeyMappingActive({
81
KeyA: {
82
value: 'a',
83
valueIsDeadKey: false,
84
withShift: 'A',
85
withShiftIsDeadKey: false,
86
withAltGr: 'å',
87
withAltGrIsDeadKey: false,
88
withShiftAltGr: 'Å',
89
withShiftAltGrIsDeadKey: false
90
},
91
KeyZ: {
92
value: 'z',
93
valueIsDeadKey: false,
94
withShift: 'Z',
95
withShiftIsDeadKey: false,
96
withAltGr: 'Ω',
97
withAltGrIsDeadKey: false,
98
withShiftAltGr: '¸',
99
withShiftAltGrIsDeadKey: false
100
}
101
}), true);
102
103
assert.strictEqual(instance.isKeyMappingActive({
104
KeyZ: {
105
value: 'y',
106
valueIsDeadKey: false,
107
withShift: 'Y',
108
withShiftIsDeadKey: false,
109
withAltGr: '¥',
110
withAltGrIsDeadKey: false,
111
withShiftAltGr: 'Ÿ',
112
withShiftAltGrIsDeadKey: false
113
},
114
}), false);
115
116
});
117
118
test('Switch keymapping', () => {
119
instance.setActiveKeyMapping({
120
KeyZ: {
121
value: 'y',
122
valueIsDeadKey: false,
123
withShift: 'Y',
124
withShiftIsDeadKey: false,
125
withAltGr: '¥',
126
withAltGrIsDeadKey: false,
127
withShiftAltGr: 'Ÿ',
128
withShiftAltGrIsDeadKey: false
129
}
130
});
131
assert.strictEqual(!!instance.activeKeyboardLayout!.isUSStandard, false);
132
assert.strictEqual(instance.isKeyMappingActive({
133
KeyZ: {
134
value: 'y',
135
valueIsDeadKey: false,
136
withShift: 'Y',
137
withShiftIsDeadKey: false,
138
withAltGr: '¥',
139
withAltGrIsDeadKey: false,
140
withShiftAltGr: 'Ÿ',
141
withShiftAltGrIsDeadKey: false
142
},
143
}), true);
144
145
instance.setUSKeyboardLayout();
146
assert.strictEqual(instance.activeKeyboardLayout!.isUSStandard, true);
147
});
148
149
test('Switch keyboard layout info', () => {
150
instance.setKeyboardLayout('com.apple.keylayout.German');
151
assert.strictEqual(!!instance.activeKeyboardLayout!.isUSStandard, false);
152
assert.strictEqual(instance.isKeyMappingActive({
153
KeyZ: {
154
value: 'y',
155
valueIsDeadKey: false,
156
withShift: 'Y',
157
withShiftIsDeadKey: false,
158
withAltGr: '¥',
159
withAltGrIsDeadKey: false,
160
withShiftAltGr: 'Ÿ',
161
withShiftAltGrIsDeadKey: false
162
},
163
}), true);
164
165
instance.setUSKeyboardLayout();
166
assert.strictEqual(instance.activeKeyboardLayout!.isUSStandard, true);
167
});
168
});
169
170