@codingame/monaco-vscode-keybindings-service-override 4.0.0 → 4.1.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.
Files changed (63) hide show
  1. package/keybindings.js +6 -6
  2. package/package.json +9 -9
  3. package/vscode/src/vs/platform/keyboardLayout/common/keyboardConfig.js +0 -50
  4. package/vscode/src/vs/platform/keyboardLayout/common/keyboardMapper.js +0 -24
  5. package/vscode/src/vs/workbench/contrib/commands/common/commands.contribution.js +0 -146
  6. package/vscode/src/vs/workbench/contrib/keybindings/browser/keybindings.contribution.js +0 -29
  7. package/vscode/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.js +0 -250
  8. package/vscode/src/vs/workbench/contrib/preferences/common/smartSnippetInserter.js +0 -126
  9. package/vscode/src/vs/workbench/services/actions/common/menusExtensionPoint.js +0 -1597
  10. package/vscode/src/vs/workbench/services/commands/common/commandService.js +0 -79
  11. package/vscode/src/vs/workbench/services/keybinding/browser/keybindingService.js +0 -947
  12. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayoutService.js +0 -502
  13. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution.js +0 -14
  14. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/cz.win.js +0 -163
  15. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/de-swiss.win.js +0 -163
  16. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/de.darwin.js +0 -126
  17. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/de.linux.js +0 -181
  18. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/de.win.js +0 -163
  19. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/dk.win.js +0 -163
  20. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/dvorak.darwin.js +0 -126
  21. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-belgian.win.js +0 -163
  22. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-ext.darwin.js +0 -126
  23. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-in.win.js +0 -163
  24. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-intl.darwin.js +0 -126
  25. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-intl.win.js +0 -163
  26. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-uk.darwin.js +0 -126
  27. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-uk.win.js +0 -163
  28. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en.darwin.js +0 -134
  29. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en.linux.js +0 -183
  30. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en.win.js +0 -168
  31. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/es-latin.win.js +0 -163
  32. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/es.darwin.js +0 -126
  33. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/es.linux.js +0 -181
  34. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/es.win.js +0 -163
  35. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/fr.darwin.js +0 -126
  36. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/fr.linux.js +0 -181
  37. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/fr.win.js +0 -163
  38. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/hu.win.js +0 -163
  39. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/it.darwin.js +0 -126
  40. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/it.win.js +0 -163
  41. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/jp-roman.darwin.js +0 -126
  42. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/jp.darwin.js +0 -126
  43. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ko.darwin.js +0 -126
  44. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.darwin.js +0 -17
  45. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.linux.js +0 -6
  46. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.win.js +0 -23
  47. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/no.win.js +0 -163
  48. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pl.darwin.js +0 -126
  49. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pl.win.js +0 -163
  50. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pt-br.win.js +0 -163
  51. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pt.darwin.js +0 -126
  52. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pt.win.js +0 -163
  53. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ru.darwin.js +0 -126
  54. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ru.linux.js +0 -181
  55. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ru.win.js +0 -163
  56. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/sv.win.js +0 -165
  57. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/thai.win.js +0 -163
  58. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/tr.win.js +0 -163
  59. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/zh-hans.darwin.js +0 -126
  60. package/vscode/src/vs/workbench/services/keybinding/common/keybindingIO.js +0 -74
  61. package/vscode/src/vs/workbench/services/keybinding/common/keymapInfo.js +0 -110
  62. package/vscode/src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.js +0 -888
  63. package/vscode/src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.js +0 -352
@@ -1,947 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
3
- import { onDidChangeFullscreen, isFullscreen } from 'vscode/vscode/vs/base/browser/browser';
4
- import { BrowserFeatures } from 'vscode/vscode/vs/base/browser/canIUse';
5
- import { onDidRegisterWindow, addDisposableListener, EventType, trackFocus, getWindow } from 'vscode/vscode/vs/base/browser/dom';
6
- import { StandardKeyboardEvent, printKeyboardEvent, printStandardKeyboardEvent } from 'vscode/vscode/vs/base/browser/keyboardEvent';
7
- import { DeferredPromise, RunOnceScheduler } from 'vscode/vscode/vs/base/common/async';
8
- import { Event, Emitter } from 'vscode/vscode/vs/base/common/event';
9
- import { parse } from 'vscode/vscode/vs/base/common/json';
10
- import { UserSettingsLabelProvider } from 'vscode/vscode/vs/base/common/keybindingLabels';
11
- import { KeybindingParser } from 'vscode/vscode/vs/base/common/keybindingParser';
12
- import { KeyCodeChord, ScanCodeChord } from 'vscode/vscode/vs/base/common/keybindings';
13
- import { KeyCodeUtils, ScanCodeUtils, IMMUTABLE_CODE_TO_KEY_CODE } from 'vscode/vscode/vs/base/common/keyCodes';
14
- import { DisposableStore, Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
15
- import { equals } from 'vscode/vscode/vs/base/common/objects';
16
- import { OS, isMacintosh } from 'vscode/vscode/vs/base/common/platform';
17
- import { dirname } from 'vscode/vscode/vs/base/common/resources';
18
- import { mainWindow } from 'vscode/vscode/vs/base/browser/window';
19
- import { MenuRegistry } from 'vscode/vscode/vs/platform/actions/common/actions';
20
- import { ICommandService, CommandsRegistry } from 'vscode/vscode/vs/platform/commands/common/commands';
21
- import { ContextKeyExpr, IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
22
- import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
23
- import { Extensions } from 'vscode/vscode/vs/platform/jsonschemas/common/jsonContributionRegistry';
24
- import { AbstractKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/abstractKeybindingService';
25
- import 'vscode/vscode/vs/platform/instantiation/common/instantiation';
26
- import { KeybindingResolver } from 'vscode/vscode/vs/platform/keybinding/common/keybindingResolver';
27
- import { KeybindingsRegistry } from 'vscode/vscode/vs/platform/keybinding/common/keybindingsRegistry';
28
- import { ResolvedKeybindingItem } from 'vscode/vscode/vs/platform/keybinding/common/resolvedKeybindingItem';
29
- import { IKeyboardLayoutService } from 'vscode/vscode/vs/platform/keyboardLayout/common/keyboardLayout';
30
- import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
31
- import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
32
- import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
33
- import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
34
- import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity';
35
- import { isLocalizedString } from 'vscode/vscode/vs/platform/action/common/action';
36
- import { commandsExtensionPoint } from '../../actions/common/menusExtensionPoint.js';
37
- import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions';
38
- import { ExtensionsRegistry } from 'vscode/vscode/vs/workbench/services/extensions/common/extensionsRegistry';
39
- import { IHostService } from 'vscode/vscode/vs/workbench/services/host/browser/host';
40
- import { getAllUnboundCommands } from 'vscode/vscode/vs/workbench/services/keybinding/browser/unboundCommands';
41
- import { KeybindingIO, OutputBuilder } from '../common/keybindingIO.js';
42
- import { IUserDataProfileService } from 'vscode/vscode/vs/workbench/services/userDataProfile/common/userDataProfile';
43
-
44
- var WorkbenchKeybindingService_1;
45
- function isValidContributedKeyBinding(keyBinding, rejects) {
46
- if (!keyBinding) {
47
- rejects.push(( localizeWithPath(
48
- 'vs/workbench/services/keybinding/browser/keybindingService',
49
- 'nonempty',
50
- "expected non-empty value."
51
- )));
52
- return false;
53
- }
54
- if (typeof keyBinding.command !== 'string') {
55
- rejects.push(( localizeWithPath(
56
- 'vs/workbench/services/keybinding/browser/keybindingService',
57
- 'requirestring',
58
- "property `{0}` is mandatory and must be of type `string`",
59
- 'command'
60
- )));
61
- return false;
62
- }
63
- if (keyBinding.key && typeof keyBinding.key !== 'string') {
64
- rejects.push(( localizeWithPath(
65
- 'vs/workbench/services/keybinding/browser/keybindingService',
66
- 'optstring',
67
- "property `{0}` can be omitted or must be of type `string`",
68
- 'key'
69
- )));
70
- return false;
71
- }
72
- if (keyBinding.when && typeof keyBinding.when !== 'string') {
73
- rejects.push(( localizeWithPath(
74
- 'vs/workbench/services/keybinding/browser/keybindingService',
75
- 'optstring',
76
- "property `{0}` can be omitted or must be of type `string`",
77
- 'when'
78
- )));
79
- return false;
80
- }
81
- if (keyBinding.mac && typeof keyBinding.mac !== 'string') {
82
- rejects.push(( localizeWithPath(
83
- 'vs/workbench/services/keybinding/browser/keybindingService',
84
- 'optstring',
85
- "property `{0}` can be omitted or must be of type `string`",
86
- 'mac'
87
- )));
88
- return false;
89
- }
90
- if (keyBinding.linux && typeof keyBinding.linux !== 'string') {
91
- rejects.push(( localizeWithPath(
92
- 'vs/workbench/services/keybinding/browser/keybindingService',
93
- 'optstring',
94
- "property `{0}` can be omitted or must be of type `string`",
95
- 'linux'
96
- )));
97
- return false;
98
- }
99
- if (keyBinding.win && typeof keyBinding.win !== 'string') {
100
- rejects.push(( localizeWithPath(
101
- 'vs/workbench/services/keybinding/browser/keybindingService',
102
- 'optstring',
103
- "property `{0}` can be omitted or must be of type `string`",
104
- 'win'
105
- )));
106
- return false;
107
- }
108
- return true;
109
- }
110
- const keybindingType = {
111
- type: 'object',
112
- default: { command: '', key: '' },
113
- properties: {
114
- command: {
115
- description: ( localizeWithPath(
116
- 'vs/workbench/services/keybinding/browser/keybindingService',
117
- 'vscode.extension.contributes.keybindings.command',
118
- 'Identifier of the command to run when keybinding is triggered.'
119
- )),
120
- type: 'string'
121
- },
122
- args: {
123
- description: ( localizeWithPath(
124
- 'vs/workbench/services/keybinding/browser/keybindingService',
125
- 'vscode.extension.contributes.keybindings.args',
126
- "Arguments to pass to the command to execute."
127
- ))
128
- },
129
- key: {
130
- description: ( localizeWithPath(
131
- 'vs/workbench/services/keybinding/browser/keybindingService',
132
- 'vscode.extension.contributes.keybindings.key',
133
- 'Key or key sequence (separate keys with plus-sign and sequences with space, e.g. Ctrl+O and Ctrl+L L for a chord).'
134
- )),
135
- type: 'string'
136
- },
137
- mac: {
138
- description: ( localizeWithPath(
139
- 'vs/workbench/services/keybinding/browser/keybindingService',
140
- 'vscode.extension.contributes.keybindings.mac',
141
- 'Mac specific key or key sequence.'
142
- )),
143
- type: 'string'
144
- },
145
- linux: {
146
- description: ( localizeWithPath(
147
- 'vs/workbench/services/keybinding/browser/keybindingService',
148
- 'vscode.extension.contributes.keybindings.linux',
149
- 'Linux specific key or key sequence.'
150
- )),
151
- type: 'string'
152
- },
153
- win: {
154
- description: ( localizeWithPath(
155
- 'vs/workbench/services/keybinding/browser/keybindingService',
156
- 'vscode.extension.contributes.keybindings.win',
157
- 'Windows specific key or key sequence.'
158
- )),
159
- type: 'string'
160
- },
161
- when: {
162
- description: ( localizeWithPath(
163
- 'vs/workbench/services/keybinding/browser/keybindingService',
164
- 'vscode.extension.contributes.keybindings.when',
165
- 'Condition when the key is active.'
166
- )),
167
- type: 'string'
168
- },
169
- }
170
- };
171
- const keybindingsExtPoint = ExtensionsRegistry.registerExtensionPoint({
172
- extensionPoint: 'keybindings',
173
- deps: [commandsExtensionPoint],
174
- jsonSchema: {
175
- description: ( localizeWithPath(
176
- 'vs/workbench/services/keybinding/browser/keybindingService',
177
- 'vscode.extension.contributes.keybindings',
178
- "Contributes keybindings."
179
- )),
180
- oneOf: [
181
- keybindingType,
182
- {
183
- type: 'array',
184
- items: keybindingType
185
- }
186
- ]
187
- }
188
- });
189
- const NUMPAD_PRINTABLE_SCANCODES = [
190
- 90 ,
191
- 91 ,
192
- 92 ,
193
- 93 ,
194
- 95 ,
195
- 96 ,
196
- 97 ,
197
- 98 ,
198
- 99 ,
199
- 100 ,
200
- 101 ,
201
- 102 ,
202
- 103 ,
203
- 104 ,
204
- 105
205
- ];
206
- const otherMacNumpadMapping = ( new Map());
207
- otherMacNumpadMapping.set(95 , 22 );
208
- otherMacNumpadMapping.set(96 , 23 );
209
- otherMacNumpadMapping.set(97 , 24 );
210
- otherMacNumpadMapping.set(98 , 25 );
211
- otherMacNumpadMapping.set(99 , 26 );
212
- otherMacNumpadMapping.set(100 , 27 );
213
- otherMacNumpadMapping.set(101 , 28 );
214
- otherMacNumpadMapping.set(102 , 29 );
215
- otherMacNumpadMapping.set(103 , 30 );
216
- otherMacNumpadMapping.set(104 , 21 );
217
- let WorkbenchKeybindingService = WorkbenchKeybindingService_1 = class WorkbenchKeybindingService extends AbstractKeybindingService {
218
- constructor(contextKeyService, commandService, telemetryService, notificationService, userDataProfileService, hostService, extensionService, fileService, uriIdentityService, logService, keyboardLayoutService) {
219
- super(contextKeyService, commandService, telemetryService, notificationService, logService);
220
- this.hostService = hostService;
221
- this.keyboardLayoutService = keyboardLayoutService;
222
- this._contributions = [];
223
- this.isComposingGlobalContextKey = contextKeyService.createKey('isComposing', false);
224
- this.kbsJsonSchema = ( new KeybindingsJsonSchema());
225
- this.updateKeybindingsJsonSchema();
226
- this._keyboardMapper = this.keyboardLayoutService.getKeyboardMapper();
227
- this._register(this.keyboardLayoutService.onDidChangeKeyboardLayout(() => {
228
- this._keyboardMapper = this.keyboardLayoutService.getKeyboardMapper();
229
- this.updateResolver();
230
- }));
231
- this._keybindingHoldMode = null;
232
- this._cachedResolver = null;
233
- this.userKeybindings = this._register(( new UserKeybindings(userDataProfileService, uriIdentityService, fileService, logService)));
234
- this.userKeybindings.initialize().then(() => {
235
- if (this.userKeybindings.keybindings.length) {
236
- this.updateResolver();
237
- }
238
- });
239
- this._register(this.userKeybindings.onDidChange(() => {
240
- logService.debug('User keybindings changed');
241
- this.updateResolver();
242
- }));
243
- keybindingsExtPoint.setHandler((extensions) => {
244
- const keybindings = [];
245
- for (const extension of extensions) {
246
- this._handleKeybindingsExtensionPointUser(extension.description.identifier, extension.description.isBuiltin, extension.value, extension.collector, keybindings);
247
- }
248
- KeybindingsRegistry.setExtensionKeybindings(keybindings);
249
- this.updateResolver();
250
- });
251
- this.updateKeybindingsJsonSchema();
252
- this._register(extensionService.onDidRegisterExtensions(() => this.updateKeybindingsJsonSchema()));
253
- this._register(Event.runAndSubscribe(onDidRegisterWindow, ({ window, disposables }) => disposables.add(this._registerKeyListeners(window)), { window: mainWindow, disposables: this._store }));
254
- this._register(onDidChangeFullscreen(windowId => {
255
- if (windowId !== mainWindow.vscodeWindowId) {
256
- return;
257
- }
258
- const keyboard = navigator.keyboard;
259
- if (BrowserFeatures.keyboard === 2 ) {
260
- return;
261
- }
262
- if (isFullscreen(mainWindow)) {
263
- keyboard?.lock(['Escape']);
264
- }
265
- else {
266
- keyboard?.unlock();
267
- }
268
- this._cachedResolver = null;
269
- this._onDidUpdateKeybindings.fire();
270
- }));
271
- }
272
- _registerKeyListeners(window) {
273
- const disposables = ( new DisposableStore());
274
- disposables.add(addDisposableListener(window, EventType.KEY_DOWN, (e) => {
275
- if (this._keybindingHoldMode) {
276
- return;
277
- }
278
- this.isComposingGlobalContextKey.set(e.isComposing);
279
- const keyEvent = ( new StandardKeyboardEvent(e));
280
- this._log(`/ Received keydown event - ${printKeyboardEvent(e)}`);
281
- this._log(`| Converted keydown event - ${printStandardKeyboardEvent(keyEvent)}`);
282
- const shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
283
- if (shouldPreventDefault) {
284
- keyEvent.preventDefault();
285
- }
286
- this.isComposingGlobalContextKey.set(false);
287
- }));
288
- disposables.add(addDisposableListener(window, EventType.KEY_UP, (e) => {
289
- this._resetKeybindingHoldMode();
290
- this.isComposingGlobalContextKey.set(e.isComposing);
291
- const keyEvent = ( new StandardKeyboardEvent(e));
292
- const shouldPreventDefault = this._singleModifierDispatch(keyEvent, keyEvent.target);
293
- if (shouldPreventDefault) {
294
- keyEvent.preventDefault();
295
- }
296
- this.isComposingGlobalContextKey.set(false);
297
- }));
298
- return disposables;
299
- }
300
- registerSchemaContribution(contribution) {
301
- this._contributions.push(contribution);
302
- if (contribution.onDidChange) {
303
- this._register(contribution.onDidChange(() => this.updateKeybindingsJsonSchema()));
304
- }
305
- this.updateKeybindingsJsonSchema();
306
- }
307
- updateKeybindingsJsonSchema() {
308
- this.kbsJsonSchema.updateSchema(this._contributions.flatMap(x => x.getSchemaAdditions()));
309
- }
310
- _printKeybinding(keybinding) {
311
- return UserSettingsLabelProvider.toLabel(OS, keybinding.chords, (chord) => {
312
- if (chord instanceof KeyCodeChord) {
313
- return ( KeyCodeUtils.toString(chord.keyCode));
314
- }
315
- return ( ScanCodeUtils.toString(chord.scanCode));
316
- }) || '[null]';
317
- }
318
- _printResolvedKeybinding(resolvedKeybinding) {
319
- return ( resolvedKeybinding.getDispatchChords().map(x => x || '[null]')).join(' ');
320
- }
321
- _printResolvedKeybindings(output, input, resolvedKeybindings) {
322
- const padLength = 35;
323
- const firstRow = `${input.padStart(padLength, ' ')} => `;
324
- if (resolvedKeybindings.length === 0) {
325
- output.push(`${firstRow}${'[NO BINDING]'.padStart(padLength, ' ')}`);
326
- return;
327
- }
328
- for (const resolvedKeybinding of resolvedKeybindings) {
329
- {
330
- output.push(`${firstRow}${this._printResolvedKeybinding(resolvedKeybinding).padStart(padLength, ' ')}`);
331
- }
332
- }
333
- }
334
- _dumpResolveKeybindingDebugInfo() {
335
- const seenBindings = ( new Set());
336
- const result = [];
337
- result.push(`Default Resolved Keybindings (unique only):`);
338
- for (const item of KeybindingsRegistry.getDefaultKeybindings()) {
339
- if (!item.keybinding) {
340
- continue;
341
- }
342
- const input = this._printKeybinding(item.keybinding);
343
- if (( seenBindings.has(input))) {
344
- continue;
345
- }
346
- seenBindings.add(input);
347
- const resolvedKeybindings = this._keyboardMapper.resolveKeybinding(item.keybinding);
348
- this._printResolvedKeybindings(result, input, resolvedKeybindings);
349
- }
350
- result.push(`User Resolved Keybindings (unique only):`);
351
- for (const item of this.userKeybindings.keybindings) {
352
- if (!item.keybinding) {
353
- continue;
354
- }
355
- const input = item._sourceKey ?? 'Impossible: missing source key, but has keybinding';
356
- if (( seenBindings.has(input))) {
357
- continue;
358
- }
359
- seenBindings.add(input);
360
- const resolvedKeybindings = this._keyboardMapper.resolveKeybinding(item.keybinding);
361
- this._printResolvedKeybindings(result, input, resolvedKeybindings);
362
- }
363
- return result.join('\n');
364
- }
365
- _dumpDebugInfo() {
366
- const layoutInfo = JSON.stringify(this.keyboardLayoutService.getCurrentKeyboardLayout(), null, '\t');
367
- const mapperInfo = this._keyboardMapper.dumpDebugInfo();
368
- const resolvedKeybindings = this._dumpResolveKeybindingDebugInfo();
369
- const rawMapping = JSON.stringify(this.keyboardLayoutService.getRawKeyboardMapping(), null, '\t');
370
- return `Layout info:\n${layoutInfo}\n\n${resolvedKeybindings}\n\n${mapperInfo}\n\nRaw mapping:\n${rawMapping}`;
371
- }
372
- _dumpDebugInfoJSON() {
373
- const info = {
374
- layout: this.keyboardLayoutService.getCurrentKeyboardLayout(),
375
- rawMapping: this.keyboardLayoutService.getRawKeyboardMapping()
376
- };
377
- return JSON.stringify(info, null, '\t');
378
- }
379
- enableKeybindingHoldMode(commandId) {
380
- if (this._currentlyDispatchingCommandId !== commandId) {
381
- return undefined;
382
- }
383
- this._keybindingHoldMode = ( new DeferredPromise());
384
- const focusTracker = trackFocus(getWindow(undefined));
385
- const listener = focusTracker.onDidBlur(() => this._resetKeybindingHoldMode());
386
- this._keybindingHoldMode.p.finally(() => {
387
- listener.dispose();
388
- focusTracker.dispose();
389
- });
390
- this._log(`+ Enabled hold-mode for ${commandId}.`);
391
- return this._keybindingHoldMode.p;
392
- }
393
- _resetKeybindingHoldMode() {
394
- if (this._keybindingHoldMode) {
395
- this._keybindingHoldMode?.complete();
396
- this._keybindingHoldMode = null;
397
- }
398
- }
399
- customKeybindingsCount() {
400
- return this.userKeybindings.keybindings.length;
401
- }
402
- updateResolver() {
403
- this._cachedResolver = null;
404
- this._onDidUpdateKeybindings.fire();
405
- }
406
- getUserKeybindingItems() {
407
- return this._resolveUserKeybindingItems(this.userKeybindings.keybindings, false);
408
- }
409
- _getResolver() {
410
- if (!this._cachedResolver) {
411
- const defaults = this._resolveKeybindingItems(KeybindingsRegistry.getDefaultKeybindings(), true);
412
- const overrides = this.getUserKeybindingItems();
413
- this._cachedResolver = ( new KeybindingResolver(defaults, overrides, (str) => this._log(str)));
414
- }
415
- return this._cachedResolver;
416
- }
417
- _documentHasFocus() {
418
- return this.hostService.hasFocus;
419
- }
420
- _resolveKeybindingItems(items, isDefault) {
421
- const result = [];
422
- let resultLen = 0;
423
- for (const item of items) {
424
- const when = item.when || undefined;
425
- const keybinding = item.keybinding;
426
- if (!keybinding) {
427
- result[resultLen++] = ( new ResolvedKeybindingItem(
428
- undefined,
429
- item.command,
430
- item.commandArgs,
431
- when,
432
- isDefault,
433
- item.extensionId,
434
- item.isBuiltinExtension
435
- ));
436
- }
437
- else {
438
- if (this._assertBrowserConflicts(keybinding)) {
439
- continue;
440
- }
441
- const resolvedKeybindings = this._keyboardMapper.resolveKeybinding(keybinding);
442
- for (let i = resolvedKeybindings.length - 1; i >= 0; i--) {
443
- const resolvedKeybinding = resolvedKeybindings[i];
444
- result[resultLen++] = ( new ResolvedKeybindingItem(
445
- resolvedKeybinding,
446
- item.command,
447
- item.commandArgs,
448
- when,
449
- isDefault,
450
- item.extensionId,
451
- item.isBuiltinExtension
452
- ));
453
- }
454
- }
455
- }
456
- return result;
457
- }
458
- _resolveUserKeybindingItems(items, isDefault) {
459
- const result = [];
460
- let resultLen = 0;
461
- for (const item of items) {
462
- const when = item.when || undefined;
463
- if (!item.keybinding) {
464
- result[resultLen++] = ( new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault, null, false));
465
- }
466
- else {
467
- const resolvedKeybindings = this._keyboardMapper.resolveKeybinding(item.keybinding);
468
- for (const resolvedKeybinding of resolvedKeybindings) {
469
- result[resultLen++] = ( new ResolvedKeybindingItem(
470
- resolvedKeybinding,
471
- item.command,
472
- item.commandArgs,
473
- when,
474
- isDefault,
475
- null,
476
- false
477
- ));
478
- }
479
- }
480
- }
481
- return result;
482
- }
483
- _assertBrowserConflicts(keybinding) {
484
- if (BrowserFeatures.keyboard === 0 ) {
485
- return false;
486
- }
487
- if (BrowserFeatures.keyboard === 1 && isFullscreen(mainWindow)) {
488
- return false;
489
- }
490
- for (const chord of keybinding.chords) {
491
- if (!chord.metaKey && !chord.altKey && !chord.ctrlKey && !chord.shiftKey) {
492
- continue;
493
- }
494
- const modifiersMask = 2048 | 512 | 1024 ;
495
- let partModifiersMask = 0;
496
- if (chord.metaKey) {
497
- partModifiersMask |= 2048 ;
498
- }
499
- if (chord.shiftKey) {
500
- partModifiersMask |= 1024 ;
501
- }
502
- if (chord.altKey) {
503
- partModifiersMask |= 512 ;
504
- }
505
- if (chord.ctrlKey && OS === 2 ) {
506
- partModifiersMask |= 256 ;
507
- }
508
- if ((partModifiersMask & modifiersMask) === ((2048 | 512) )) {
509
- if (chord instanceof ScanCodeChord && ((chord.scanCode === 86 || chord.scanCode === 85) )) {
510
- return true;
511
- }
512
- if (chord instanceof KeyCodeChord && ((chord.keyCode === 15 || chord.keyCode === 17) )) {
513
- return true;
514
- }
515
- }
516
- if ((partModifiersMask & modifiersMask) === 2048 ) {
517
- if (chord instanceof ScanCodeChord && ((chord.scanCode >= 36 && chord.scanCode <= 45) )) {
518
- return true;
519
- }
520
- if (chord instanceof KeyCodeChord && ((chord.keyCode >= 21 && chord.keyCode <= 30) )) {
521
- return true;
522
- }
523
- }
524
- }
525
- return false;
526
- }
527
- resolveKeybinding(kb) {
528
- return this._keyboardMapper.resolveKeybinding(kb);
529
- }
530
- resolveKeyboardEvent(keyboardEvent) {
531
- this.keyboardLayoutService.validateCurrentKeyboardMapping(keyboardEvent);
532
- return this._keyboardMapper.resolveKeyboardEvent(keyboardEvent);
533
- }
534
- resolveUserBinding(userBinding) {
535
- const keybinding = KeybindingParser.parseKeybinding(userBinding);
536
- return (keybinding ? this._keyboardMapper.resolveKeybinding(keybinding) : []);
537
- }
538
- _handleKeybindingsExtensionPointUser(extensionId, isBuiltin, keybindings, collector, result) {
539
- if (Array.isArray(keybindings)) {
540
- for (let i = 0, len = keybindings.length; i < len; i++) {
541
- this._handleKeybinding(extensionId, isBuiltin, i + 1, keybindings[i], collector, result);
542
- }
543
- }
544
- else {
545
- this._handleKeybinding(extensionId, isBuiltin, 1, keybindings, collector, result);
546
- }
547
- }
548
- _handleKeybinding(extensionId, isBuiltin, idx, keybindings, collector, result) {
549
- const rejects = [];
550
- if (isValidContributedKeyBinding(keybindings, rejects)) {
551
- const rule = this._asCommandRule(extensionId, isBuiltin, idx++, keybindings);
552
- if (rule) {
553
- result.push(rule);
554
- }
555
- }
556
- if (rejects.length > 0) {
557
- collector.error(( localizeWithPath(
558
- 'vs/workbench/services/keybinding/browser/keybindingService',
559
- 'invalid.keybindings',
560
- "Invalid `contributes.{0}`: {1}",
561
- keybindingsExtPoint.name,
562
- rejects.join('\n')
563
- )));
564
- }
565
- }
566
- static bindToCurrentPlatform(key, mac, linux, win) {
567
- if (OS === 1 && win) {
568
- if (win) {
569
- return win;
570
- }
571
- }
572
- else if (OS === 2 ) {
573
- if (mac) {
574
- return mac;
575
- }
576
- }
577
- else {
578
- if (linux) {
579
- return linux;
580
- }
581
- }
582
- return key;
583
- }
584
- _asCommandRule(extensionId, isBuiltin, idx, binding) {
585
- const { command, args, when, key, mac, linux, win } = binding;
586
- const keybinding = WorkbenchKeybindingService_1.bindToCurrentPlatform(key, mac, linux, win);
587
- if (!keybinding) {
588
- return undefined;
589
- }
590
- let weight;
591
- if (isBuiltin) {
592
- weight = 300 + idx;
593
- }
594
- else {
595
- weight = 400 + idx;
596
- }
597
- const commandAction = MenuRegistry.getCommand(command);
598
- const precondition = commandAction && commandAction.precondition;
599
- let fullWhen;
600
- if (when && precondition) {
601
- fullWhen = ( ContextKeyExpr.and(precondition, ContextKeyExpr.deserialize(when)));
602
- }
603
- else if (when) {
604
- fullWhen = ContextKeyExpr.deserialize(when);
605
- }
606
- else if (precondition) {
607
- fullWhen = precondition;
608
- }
609
- const desc = {
610
- id: command,
611
- args,
612
- when: fullWhen,
613
- weight: weight,
614
- keybinding: KeybindingParser.parseKeybinding(keybinding),
615
- extensionId: extensionId.value,
616
- isBuiltinExtension: isBuiltin
617
- };
618
- return desc;
619
- }
620
- getDefaultKeybindingsContent() {
621
- const resolver = this._getResolver();
622
- const defaultKeybindings = resolver.getDefaultKeybindings();
623
- const boundCommands = resolver.getDefaultBoundCommands();
624
- return (WorkbenchKeybindingService_1._getDefaultKeybindings(defaultKeybindings)
625
- + '\n\n'
626
- + WorkbenchKeybindingService_1._getAllCommandsAsComment(boundCommands));
627
- }
628
- static _getDefaultKeybindings(defaultKeybindings) {
629
- const out = ( new OutputBuilder());
630
- out.writeLine('[');
631
- const lastIndex = defaultKeybindings.length - 1;
632
- defaultKeybindings.forEach((k, index) => {
633
- KeybindingIO.writeKeybindingItem(out, k);
634
- if (index !== lastIndex) {
635
- out.writeLine(',');
636
- }
637
- else {
638
- out.writeLine();
639
- }
640
- });
641
- out.writeLine(']');
642
- return ( out.toString());
643
- }
644
- static _getAllCommandsAsComment(boundCommands) {
645
- const unboundCommands = getAllUnboundCommands(boundCommands);
646
- const pretty = unboundCommands.sort().join('\n// - ');
647
- return '// ' + ( localizeWithPath(
648
- 'vs/workbench/services/keybinding/browser/keybindingService',
649
- 'unboundCommands',
650
- "Here are other available commands: "
651
- )) + '\n// - ' + pretty;
652
- }
653
- mightProducePrintableCharacter(event) {
654
- if (event.ctrlKey || event.metaKey || event.altKey) {
655
- return false;
656
- }
657
- const code = ScanCodeUtils.toEnum(event.code);
658
- if (NUMPAD_PRINTABLE_SCANCODES.indexOf(code) !== -1) {
659
- if (event.keyCode === IMMUTABLE_CODE_TO_KEY_CODE[code]) {
660
- return true;
661
- }
662
- if (isMacintosh && event.keyCode === otherMacNumpadMapping.get(code)) {
663
- return true;
664
- }
665
- return false;
666
- }
667
- const keycode = IMMUTABLE_CODE_TO_KEY_CODE[code];
668
- if (keycode !== -1) {
669
- return false;
670
- }
671
- const mapping = this.keyboardLayoutService.getRawKeyboardMapping();
672
- if (!mapping) {
673
- return false;
674
- }
675
- const keyInfo = mapping[event.code];
676
- if (!keyInfo) {
677
- return false;
678
- }
679
- if (!keyInfo.value || /\s/.test(keyInfo.value)) {
680
- return false;
681
- }
682
- return true;
683
- }
684
- };
685
- WorkbenchKeybindingService = WorkbenchKeybindingService_1 = ( __decorate([
686
- ( __param(0, IContextKeyService)),
687
- ( __param(1, ICommandService)),
688
- ( __param(2, ITelemetryService)),
689
- ( __param(3, INotificationService)),
690
- ( __param(4, IUserDataProfileService)),
691
- ( __param(5, IHostService)),
692
- ( __param(6, IExtensionService)),
693
- ( __param(7, IFileService)),
694
- ( __param(8, IUriIdentityService)),
695
- ( __param(9, ILogService)),
696
- ( __param(10, IKeyboardLayoutService))
697
- ], WorkbenchKeybindingService));
698
- class UserKeybindings extends Disposable {
699
- get keybindings() { return this._keybindings; }
700
- constructor(userDataProfileService, uriIdentityService, fileService, logService) {
701
- super();
702
- this.userDataProfileService = userDataProfileService;
703
- this.uriIdentityService = uriIdentityService;
704
- this.fileService = fileService;
705
- this._rawKeybindings = [];
706
- this._keybindings = [];
707
- this.watchDisposables = this._register(( new DisposableStore()));
708
- this._onDidChange = this._register(( new Emitter()));
709
- this.onDidChange = this._onDidChange.event;
710
- this.watch();
711
- this.reloadConfigurationScheduler = this._register(( new RunOnceScheduler(() => this.reload().then(changed => {
712
- if (changed) {
713
- this._onDidChange.fire();
714
- }
715
- }), 50)));
716
- this._register(Event.filter(this.fileService.onDidFilesChange, e => e.contains(this.userDataProfileService.currentProfile.keybindingsResource))(() => {
717
- logService.debug('Keybindings file changed');
718
- this.reloadConfigurationScheduler.schedule();
719
- }));
720
- this._register(this.fileService.onDidRunOperation((e) => {
721
- if (e.operation === 4 && ( e.resource.toString()) === ( this.userDataProfileService.currentProfile.keybindingsResource.toString())) {
722
- logService.debug('Keybindings file written');
723
- this.reloadConfigurationScheduler.schedule();
724
- }
725
- }));
726
- this._register(userDataProfileService.onDidChangeCurrentProfile(e => {
727
- if (!this.uriIdentityService.extUri.isEqual(e.previous.keybindingsResource, e.profile.keybindingsResource)) {
728
- e.join(this.whenCurrentProfileChanged());
729
- }
730
- }));
731
- }
732
- async whenCurrentProfileChanged() {
733
- this.watch();
734
- this.reloadConfigurationScheduler.schedule();
735
- }
736
- watch() {
737
- this.watchDisposables.clear();
738
- this.watchDisposables.add(this.fileService.watch(dirname(this.userDataProfileService.currentProfile.keybindingsResource)));
739
- this.watchDisposables.add(this.fileService.watch(this.userDataProfileService.currentProfile.keybindingsResource));
740
- }
741
- async initialize() {
742
- await this.reload();
743
- }
744
- async reload() {
745
- const newKeybindings = await this.readUserKeybindings();
746
- if (equals(this._rawKeybindings, newKeybindings)) {
747
- return false;
748
- }
749
- this._rawKeybindings = newKeybindings;
750
- this._keybindings = ( this._rawKeybindings.map((k) => KeybindingIO.readUserKeybindingItem(k)));
751
- return true;
752
- }
753
- async readUserKeybindings() {
754
- try {
755
- const content = await this.fileService.readFile(this.userDataProfileService.currentProfile.keybindingsResource);
756
- const value = parse(( content.value.toString()));
757
- return Array.isArray(value)
758
- ? value.filter(v => v && typeof v === 'object' )
759
- : [];
760
- }
761
- catch (e) {
762
- return [];
763
- }
764
- }
765
- }
766
- class KeybindingsJsonSchema {
767
- static { this.schemaId = 'vscode://schemas/keybindings'; }
768
- constructor() {
769
- this.commandsSchemas = [];
770
- this.commandsEnum = [];
771
- this.removalCommandsEnum = [];
772
- this.commandsEnumDescriptions = [];
773
- this.schema = {
774
- id: KeybindingsJsonSchema.schemaId,
775
- type: 'array',
776
- title: ( localizeWithPath(
777
- 'vs/workbench/services/keybinding/browser/keybindingService',
778
- 'keybindings.json.title',
779
- "Keybindings configuration"
780
- )),
781
- allowTrailingCommas: true,
782
- allowComments: true,
783
- definitions: {
784
- 'editorGroupsSchema': {
785
- 'type': 'array',
786
- 'items': {
787
- 'type': 'object',
788
- 'properties': {
789
- 'groups': {
790
- '$ref': '#/definitions/editorGroupsSchema',
791
- 'default': [{}, {}]
792
- },
793
- 'size': {
794
- 'type': 'number',
795
- 'default': 0.5
796
- }
797
- }
798
- }
799
- },
800
- 'commandNames': {
801
- 'type': 'string',
802
- 'enum': this.commandsEnum,
803
- 'enumDescriptions': this.commandsEnumDescriptions,
804
- 'description': ( localizeWithPath(
805
- 'vs/workbench/services/keybinding/browser/keybindingService',
806
- 'keybindings.json.command',
807
- "Name of the command to execute"
808
- )),
809
- },
810
- 'commandType': {
811
- 'anyOf': [
812
- {
813
- $ref: '#/definitions/commandNames'
814
- },
815
- {
816
- 'type': 'string',
817
- 'enum': this.removalCommandsEnum,
818
- 'enumDescriptions': this.commandsEnumDescriptions,
819
- 'description': ( localizeWithPath(
820
- 'vs/workbench/services/keybinding/browser/keybindingService',
821
- 'keybindings.json.removalCommand',
822
- "Name of the command to remove keyboard shortcut for"
823
- )),
824
- },
825
- {
826
- 'type': 'string'
827
- },
828
- ]
829
- },
830
- 'commandsSchemas': {
831
- 'allOf': this.commandsSchemas
832
- }
833
- },
834
- items: {
835
- 'required': ['key'],
836
- 'type': 'object',
837
- 'defaultSnippets': [{ 'body': { 'key': '$1', 'command': '$2', 'when': '$3' } }],
838
- 'properties': {
839
- 'key': {
840
- 'type': 'string',
841
- 'description': ( localizeWithPath(
842
- 'vs/workbench/services/keybinding/browser/keybindingService',
843
- 'keybindings.json.key',
844
- "Key or key sequence (separated by space)"
845
- )),
846
- },
847
- 'command': {
848
- 'anyOf': [
849
- {
850
- 'if': {
851
- 'type': 'array'
852
- },
853
- 'then': {
854
- 'not': {
855
- 'type': 'array'
856
- },
857
- 'errorMessage': ( localizeWithPath(
858
- 'vs/workbench/services/keybinding/browser/keybindingService',
859
- 'keybindings.commandsIsArray',
860
- "Incorrect type. Expected \"{0}\". The field 'command' does not support running multiple commands. Use command 'runCommands' to pass it multiple commands to run.",
861
- 'string'
862
- ))
863
- },
864
- 'else': {
865
- '$ref': '#/definitions/commandType'
866
- }
867
- },
868
- {
869
- '$ref': '#/definitions/commandType'
870
- }
871
- ]
872
- },
873
- 'when': {
874
- 'type': 'string',
875
- 'description': ( localizeWithPath(
876
- 'vs/workbench/services/keybinding/browser/keybindingService',
877
- 'keybindings.json.when',
878
- "Condition when the key is active."
879
- ))
880
- },
881
- 'args': {
882
- 'description': ( localizeWithPath(
883
- 'vs/workbench/services/keybinding/browser/keybindingService',
884
- 'keybindings.json.args',
885
- "Arguments to pass to the command to execute."
886
- ))
887
- }
888
- },
889
- '$ref': '#/definitions/commandsSchemas'
890
- }
891
- };
892
- this.schemaRegistry = ( Registry.as(Extensions.JSONContribution));
893
- this.schemaRegistry.registerSchema(KeybindingsJsonSchema.schemaId, this.schema);
894
- }
895
- updateSchema(additionalContributions) {
896
- this.commandsSchemas.length = 0;
897
- this.commandsEnum.length = 0;
898
- this.removalCommandsEnum.length = 0;
899
- this.commandsEnumDescriptions.length = 0;
900
- const knownCommands = ( new Set());
901
- const addKnownCommand = (commandId, description) => {
902
- if (!/^_/.test(commandId)) {
903
- if (!( knownCommands.has(commandId))) {
904
- knownCommands.add(commandId);
905
- this.commandsEnum.push(commandId);
906
- this.commandsEnumDescriptions.push(isLocalizedString(description) ? description.value : description);
907
- this.removalCommandsEnum.push(`-${commandId}`);
908
- }
909
- }
910
- };
911
- const allCommands = CommandsRegistry.getCommands();
912
- for (const [commandId, command] of allCommands) {
913
- const commandMetadata = command.metadata;
914
- addKnownCommand(commandId, commandMetadata?.description);
915
- if (!commandMetadata || !commandMetadata.args || commandMetadata.args.length !== 1 || !commandMetadata.args[0].schema) {
916
- continue;
917
- }
918
- const argsSchema = commandMetadata.args[0].schema;
919
- const argsRequired = ((typeof commandMetadata.args[0].isOptional !== 'undefined')
920
- ? (!commandMetadata.args[0].isOptional)
921
- : (Array.isArray(argsSchema.required) && argsSchema.required.length > 0));
922
- const addition = {
923
- 'if': {
924
- 'required': ['command'],
925
- 'properties': {
926
- 'command': { 'const': commandId }
927
- }
928
- },
929
- 'then': {
930
- 'required': [].concat(argsRequired ? ['args'] : []),
931
- 'properties': {
932
- 'args': argsSchema
933
- }
934
- }
935
- };
936
- this.commandsSchemas.push(addition);
937
- }
938
- const menuCommands = MenuRegistry.getCommands();
939
- for (const commandId of ( menuCommands.keys())) {
940
- addKnownCommand(commandId);
941
- }
942
- this.commandsSchemas.push(...additionalContributions);
943
- this.schemaRegistry.notifySchemaChanged(KeybindingsJsonSchema.schemaId);
944
- }
945
- }
946
-
947
- export { WorkbenchKeybindingService };