@codingame/monaco-vscode-keybindings-service-override 4.1.0 → 4.1.1

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 +50 -0
  4. package/vscode/src/vs/platform/keyboardLayout/common/keyboardMapper.js +24 -0
  5. package/vscode/src/vs/workbench/contrib/commands/common/commands.contribution.js +146 -0
  6. package/vscode/src/vs/workbench/contrib/keybindings/browser/keybindings.contribution.js +29 -0
  7. package/vscode/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.js +250 -0
  8. package/vscode/src/vs/workbench/contrib/preferences/common/smartSnippetInserter.js +126 -0
  9. package/vscode/src/vs/workbench/services/actions/common/menusExtensionPoint.js +1597 -0
  10. package/vscode/src/vs/workbench/services/commands/common/commandService.js +79 -0
  11. package/vscode/src/vs/workbench/services/keybinding/browser/keybindingService.js +947 -0
  12. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayoutService.js +502 -0
  13. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution.js +14 -0
  14. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/cz.win.js +163 -0
  15. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/de-swiss.win.js +163 -0
  16. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/de.darwin.js +126 -0
  17. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/de.linux.js +181 -0
  18. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/de.win.js +163 -0
  19. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/dk.win.js +163 -0
  20. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/dvorak.darwin.js +126 -0
  21. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-belgian.win.js +163 -0
  22. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-ext.darwin.js +126 -0
  23. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-in.win.js +163 -0
  24. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-intl.darwin.js +126 -0
  25. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-intl.win.js +163 -0
  26. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-uk.darwin.js +126 -0
  27. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en-uk.win.js +163 -0
  28. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en.darwin.js +134 -0
  29. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en.linux.js +183 -0
  30. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en.win.js +168 -0
  31. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/es-latin.win.js +163 -0
  32. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/es.darwin.js +126 -0
  33. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/es.linux.js +181 -0
  34. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/es.win.js +163 -0
  35. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/fr.darwin.js +126 -0
  36. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/fr.linux.js +181 -0
  37. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/fr.win.js +163 -0
  38. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/hu.win.js +163 -0
  39. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/it.darwin.js +126 -0
  40. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/it.win.js +163 -0
  41. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/jp-roman.darwin.js +126 -0
  42. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/jp.darwin.js +126 -0
  43. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ko.darwin.js +126 -0
  44. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.darwin.js +17 -0
  45. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.linux.js +6 -0
  46. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.win.js +23 -0
  47. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/no.win.js +163 -0
  48. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pl.darwin.js +126 -0
  49. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pl.win.js +163 -0
  50. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pt-br.win.js +163 -0
  51. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pt.darwin.js +126 -0
  52. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/pt.win.js +163 -0
  53. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ru.darwin.js +126 -0
  54. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ru.linux.js +181 -0
  55. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ru.win.js +163 -0
  56. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/sv.win.js +165 -0
  57. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/thai.win.js +163 -0
  58. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/tr.win.js +163 -0
  59. package/vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/zh-hans.darwin.js +126 -0
  60. package/vscode/src/vs/workbench/services/keybinding/common/keybindingIO.js +74 -0
  61. package/vscode/src/vs/workbench/services/keybinding/common/keymapInfo.js +110 -0
  62. package/vscode/src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.js +888 -0
  63. package/vscode/src/vs/workbench/services/keybinding/common/windowsKeyboardMapper.js +352 -0
package/keybindings.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { __decorate, __param } from './external/tslib/tslib.es6.js';
2
2
  import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/descriptors';
3
- import { WorkbenchKeybindingService } from 'vscode/vscode/vs/workbench/services/keybinding/browser/keybindingService';
3
+ import { WorkbenchKeybindingService } from './vscode/src/vs/workbench/services/keybinding/browser/keybindingService.js';
4
4
  import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
5
5
  import { VSBuffer } from 'vscode/vscode/vs/base/common/buffer';
6
6
  import { IUserDataProfilesService } from 'vscode/vscode/vs/platform/userDataProfile/common/userDataProfile';
7
7
  import { IKeyboardLayoutService } from 'vscode/vscode/vs/platform/keyboardLayout/common/keyboardLayout';
8
- import { BrowserKeyboardLayoutService } from 'vscode/vscode/vs/workbench/services/keybinding/browser/keyboardLayoutService';
8
+ import { BrowserKeyboardLayoutService } from './vscode/src/vs/workbench/services/keybinding/browser/keyboardLayoutService.js';
9
9
  import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
10
10
  import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands';
11
- import { CommandService } from 'vscode/vscode/vs/workbench/services/commands/common/commandService';
11
+ import { CommandService } from './vscode/src/vs/workbench/services/commands/common/commandService.js';
12
12
  import { DisposableStore, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
13
13
  import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
14
14
  import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity';
@@ -25,9 +25,9 @@ import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/c
25
25
  import getServiceOverride$1, { initFile } from '@codingame/monaco-vscode-files-service-override';
26
26
  import { onRenderWorkbench } from 'vscode/lifecycle';
27
27
  import 'vscode/vscode/vs/workbench/browser/workbench.contribution';
28
- import 'vscode/vscode/vs/workbench/contrib/keybindings/browser/keybindings.contribution';
29
- import 'vscode/vscode/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution';
30
- import 'vscode/vscode/vs/workbench/contrib/commands/common/commands.contribution';
28
+ import './vscode/src/vs/workbench/contrib/keybindings/browser/keybindings.contribution.js';
29
+ import './vscode/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.js';
30
+ import './vscode/src/vs/workbench/contrib/commands/common/commands.contribution.js';
31
31
  import { getService } from 'vscode/services';
32
32
 
33
33
  const defaultUserKeybindindsFile = ( URI.from({ scheme: Schemas.vscodeUserData, path: '/User/keybindings.json' }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-keybindings-service-override",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,13 +18,13 @@
18
18
  "module": "index.js",
19
19
  "types": "index.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@4.1.0",
22
- "@codingame/monaco-vscode-files-service-override": "4.1.0",
23
- "@codingame/monaco-vscode-quickaccess-service-override": "4.1.0",
24
- "@codingame/monaco-vscode-extensions-service-override": "4.1.0",
25
- "@codingame/monaco-vscode-environment-service-override": "4.1.0",
26
- "@codingame/monaco-vscode-layout-service-override": "4.1.0",
27
- "@codingame/monaco-vscode-host-service-override": "4.1.0",
28
- "@codingame/monaco-vscode-base-service-override": "4.1.0"
21
+ "vscode": "npm:@codingame/monaco-vscode-api@4.1.1",
22
+ "@codingame/monaco-vscode-files-service-override": "4.1.1",
23
+ "@codingame/monaco-vscode-quickaccess-service-override": "4.1.1",
24
+ "@codingame/monaco-vscode-extensions-service-override": "4.1.1",
25
+ "@codingame/monaco-vscode-environment-service-override": "4.1.1",
26
+ "@codingame/monaco-vscode-layout-service-override": "4.1.1",
27
+ "@codingame/monaco-vscode-host-service-override": "4.1.1",
28
+ "@codingame/monaco-vscode-base-service-override": "4.1.1"
29
29
  }
30
30
  }
@@ -0,0 +1,50 @@
1
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
2
+ import { OS } from 'vscode/vscode/vs/base/common/platform';
3
+ import { Extensions } from 'vscode/vscode/vs/platform/configuration/common/configurationRegistry';
4
+ import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
5
+
6
+ function readKeyboardConfig(configurationService) {
7
+ const keyboard = configurationService.getValue('keyboard');
8
+ const dispatch = ((keyboard?.dispatch === 'keyCode' ? 1 : 0) );
9
+ const mapAltGrToCtrlAlt = Boolean(keyboard?.mapAltGrToCtrlAlt);
10
+ return { dispatch, mapAltGrToCtrlAlt };
11
+ }
12
+ const configurationRegistry = ( Registry.as(Extensions.Configuration));
13
+ const keyboardConfiguration = {
14
+ 'id': 'keyboard',
15
+ 'order': 15,
16
+ 'type': 'object',
17
+ 'title': ( localizeWithPath(
18
+ 'vs/platform/keyboardLayout/common/keyboardConfig',
19
+ 'keyboardConfigurationTitle',
20
+ "Keyboard"
21
+ )),
22
+ 'properties': {
23
+ 'keyboard.dispatch': {
24
+ scope: 1 ,
25
+ type: 'string',
26
+ enum: ['code', 'keyCode'],
27
+ default: 'code',
28
+ markdownDescription: ( localizeWithPath(
29
+ 'vs/platform/keyboardLayout/common/keyboardConfig',
30
+ 'dispatch',
31
+ "Controls the dispatching logic for key presses to use either `code` (recommended) or `keyCode`."
32
+ )),
33
+ included: OS === 2 || OS === 3
34
+ },
35
+ 'keyboard.mapAltGrToCtrlAlt': {
36
+ scope: 1 ,
37
+ type: 'boolean',
38
+ default: false,
39
+ markdownDescription: ( localizeWithPath(
40
+ 'vs/platform/keyboardLayout/common/keyboardConfig',
41
+ 'mapAltGrToCtrlAlt',
42
+ "Controls if the AltGraph+ modifier should be treated as Ctrl+Alt+."
43
+ )),
44
+ included: OS === 1
45
+ }
46
+ }
47
+ };
48
+ configurationRegistry.registerConfiguration(keyboardConfiguration);
49
+
50
+ export { readKeyboardConfig };
@@ -0,0 +1,24 @@
1
+ class CachedKeyboardMapper {
2
+ constructor(actual) {
3
+ this._actual = actual;
4
+ this._cache = ( new Map());
5
+ }
6
+ dumpDebugInfo() {
7
+ return this._actual.dumpDebugInfo();
8
+ }
9
+ resolveKeyboardEvent(keyboardEvent) {
10
+ return this._actual.resolveKeyboardEvent(keyboardEvent);
11
+ }
12
+ resolveKeybinding(keybinding) {
13
+ const hashCode = keybinding.getHashCode();
14
+ const resolved = this._cache.get(hashCode);
15
+ if (!resolved) {
16
+ const r = this._actual.resolveKeybinding(keybinding);
17
+ this._cache.set(hashCode, r);
18
+ return r;
19
+ }
20
+ return resolved;
21
+ }
22
+ }
23
+
24
+ export { CachedKeyboardMapper };
@@ -0,0 +1,146 @@
1
+ import { localize2WithPath, localizeWithPath } from 'vscode/vscode/vs/nls';
2
+ import { registerAction2, Action2 } from 'vscode/vscode/vs/platform/actions/common/actions';
3
+ import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands';
4
+ import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
5
+ import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
6
+
7
+ class RunCommands extends Action2 {
8
+ constructor() {
9
+ super({
10
+ id: 'runCommands',
11
+ title: ( localize2WithPath(
12
+ 'vs/workbench/contrib/commands/common/commands.contribution',
13
+ 'runCommands',
14
+ "Run Commands"
15
+ )),
16
+ f1: false,
17
+ metadata: {
18
+ description: ( localizeWithPath(
19
+ 'vs/workbench/contrib/commands/common/commands.contribution',
20
+ 'runCommands.description',
21
+ "Run several commands"
22
+ )),
23
+ args: [
24
+ {
25
+ name: 'args',
26
+ schema: {
27
+ type: 'object',
28
+ required: ['commands'],
29
+ properties: {
30
+ commands: {
31
+ type: 'array',
32
+ description: ( localizeWithPath(
33
+ 'vs/workbench/contrib/commands/common/commands.contribution',
34
+ 'runCommands.commands',
35
+ "Commands to run"
36
+ )),
37
+ items: {
38
+ anyOf: [
39
+ {
40
+ $ref: 'vscode://schemas/keybindings#/definitions/commandNames'
41
+ },
42
+ {
43
+ type: 'string',
44
+ },
45
+ {
46
+ type: 'object',
47
+ required: ['command'],
48
+ properties: {
49
+ command: {
50
+ 'anyOf': [
51
+ {
52
+ $ref: 'vscode://schemas/keybindings#/definitions/commandNames'
53
+ },
54
+ {
55
+ type: 'string'
56
+ },
57
+ ]
58
+ }
59
+ },
60
+ $ref: 'vscode://schemas/keybindings#/definitions/commandsSchemas'
61
+ }
62
+ ]
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ]
69
+ }
70
+ });
71
+ }
72
+ async run(accessor, args) {
73
+ const notificationService = accessor.get(INotificationService);
74
+ if (!this._isCommandArgs(args)) {
75
+ notificationService.error(( localizeWithPath(
76
+ 'vs/workbench/contrib/commands/common/commands.contribution',
77
+ 'runCommands.invalidArgs',
78
+ "'runCommands' has received an argument with incorrect type. Please, review the argument passed to the command."
79
+ )));
80
+ return;
81
+ }
82
+ if (args.commands.length === 0) {
83
+ notificationService.warn(( localizeWithPath(
84
+ 'vs/workbench/contrib/commands/common/commands.contribution',
85
+ 'runCommands.noCommandsToRun',
86
+ "'runCommands' has not received commands to run. Did you forget to pass commands in the 'runCommands' argument?"
87
+ )));
88
+ return;
89
+ }
90
+ const commandService = accessor.get(ICommandService);
91
+ const logService = accessor.get(ILogService);
92
+ let i = 0;
93
+ try {
94
+ for (; i < args.commands.length; ++i) {
95
+ const cmd = args.commands[i];
96
+ logService.debug(`runCommands: executing ${i}-th command: ${JSON.stringify(cmd)}`);
97
+ const r = await this._runCommand(commandService, cmd);
98
+ logService.debug(`runCommands: executed ${i}-th command with return value: ${JSON.stringify(r)}`);
99
+ }
100
+ }
101
+ catch (err) {
102
+ logService.debug(`runCommands: executing ${i}-th command resulted in an error: ${err instanceof Error ? err.message : JSON.stringify(err)}`);
103
+ notificationService.error(err);
104
+ }
105
+ }
106
+ _isCommandArgs(args) {
107
+ if (!args || typeof args !== 'object') {
108
+ return false;
109
+ }
110
+ if (!('commands' in args) || !Array.isArray(args.commands)) {
111
+ return false;
112
+ }
113
+ for (const cmd of args.commands) {
114
+ if (typeof cmd === 'string') {
115
+ continue;
116
+ }
117
+ if (typeof cmd === 'object' && typeof cmd.command === 'string') {
118
+ continue;
119
+ }
120
+ return false;
121
+ }
122
+ return true;
123
+ }
124
+ _runCommand(commandService, cmd) {
125
+ let commandID, commandArgs;
126
+ if (typeof cmd === 'string') {
127
+ commandID = cmd;
128
+ }
129
+ else {
130
+ commandID = cmd.command;
131
+ commandArgs = cmd.args;
132
+ }
133
+ if (commandArgs === undefined) {
134
+ return commandService.executeCommand(commandID);
135
+ }
136
+ else {
137
+ if (Array.isArray(commandArgs)) {
138
+ return commandService.executeCommand(commandID, ...commandArgs);
139
+ }
140
+ else {
141
+ return commandService.executeCommand(commandID, commandArgs);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ registerAction2(RunCommands);
@@ -0,0 +1,29 @@
1
+ import { localize2WithPath } from 'vscode/vscode/vs/nls';
2
+ import { registerAction2, Action2 } from 'vscode/vscode/vs/platform/actions/common/actions';
3
+ import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
4
+ import { Categories } from 'vscode/vscode/vs/platform/action/common/actionCommonCategories';
5
+ import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands';
6
+ import { showWindowLogActionId } from 'vscode/vscode/vs/workbench/services/log/common/logConstants';
7
+
8
+ class ToggleKeybindingsLogAction extends Action2 {
9
+ constructor() {
10
+ super({
11
+ id: 'workbench.action.toggleKeybindingsLog',
12
+ title: ( localize2WithPath(
13
+ 'vs/workbench/contrib/keybindings/browser/keybindings.contribution',
14
+ 'toggleKeybindingsLog',
15
+ "Toggle Keyboard Shortcuts Troubleshooting"
16
+ )),
17
+ category: Categories.Developer,
18
+ f1: true
19
+ });
20
+ }
21
+ run(accessor) {
22
+ const logging = accessor.get(IKeybindingService).toggleLogging();
23
+ if (logging) {
24
+ const commandService = accessor.get(ICommandService);
25
+ commandService.executeCommand(showWindowLogActionId);
26
+ }
27
+ }
28
+ }
29
+ registerAction2(ToggleKeybindingsLogAction);
@@ -0,0 +1,250 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
3
+ import { RunOnceScheduler } from 'vscode/vscode/vs/base/common/async';
4
+ import { MarkdownString } from 'vscode/vscode/vs/base/common/htmlContent';
5
+ import { Disposable, MutableDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
6
+ import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
7
+ import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
8
+ import { Range } from 'vscode/vscode/vs/editor/common/core/range';
9
+ import { registerEditorContribution } from 'vscode/vscode/vs/editor/browser/editorExtensions';
10
+ import { SnippetController2 } from 'vscode/vscode/vs/editor/contrib/snippet/browser/snippetController2';
11
+ import { SmartSnippetInserter } from '../common/smartSnippetInserter.js';
12
+ import { DefineKeybindingOverlayWidget } from 'vscode/vscode/vs/workbench/contrib/preferences/browser/keybindingWidgets';
13
+ import { parseTree } from 'vscode/vscode/vs/base/common/json';
14
+ import { WindowsNativeResolvedKeybinding } from '../../../services/keybinding/common/windowsKeyboardMapper.js';
15
+ import { themeColorFromId } from 'vscode/vscode/vs/platform/theme/common/themeService';
16
+ import { overviewRulerError, overviewRulerInfo } from 'vscode/vscode/vs/editor/common/core/editorColorRegistry';
17
+ import { OverviewRulerLane } from 'vscode/vscode/vs/editor/common/model';
18
+ import { KeybindingParser } from 'vscode/vscode/vs/base/common/keybindingParser';
19
+ import { assertIsDefined } from 'vscode/vscode/vs/base/common/types';
20
+ import { isEqual } from 'vscode/vscode/vs/base/common/resources';
21
+ import { IUserDataProfileService } from 'vscode/vscode/vs/workbench/services/userDataProfile/common/userDataProfile';
22
+ import { DEFINE_KEYBINDING_EDITOR_CONTRIB_ID } from 'vscode/vscode/vs/workbench/services/preferences/common/preferences';
23
+
24
+ var KeybindingEditorDecorationsRenderer_1;
25
+ const NLS_KB_LAYOUT_ERROR_MESSAGE = ( localizeWithPath(
26
+ 'vs/workbench/contrib/preferences/browser/keybindingsEditorContribution',
27
+ 'defineKeybinding.kbLayoutErrorMessage',
28
+ "You won't be able to produce this key combination under your current keyboard layout."
29
+ ));
30
+ let DefineKeybindingEditorContribution = class DefineKeybindingEditorContribution extends Disposable {
31
+ constructor(_editor, _instantiationService, _userDataProfileService) {
32
+ super();
33
+ this._editor = _editor;
34
+ this._instantiationService = _instantiationService;
35
+ this._userDataProfileService = _userDataProfileService;
36
+ this._keybindingDecorationRenderer = this._register(( new MutableDisposable()));
37
+ this._defineWidget = this._register(this._instantiationService.createInstance(DefineKeybindingOverlayWidget, this._editor));
38
+ this._register(this._editor.onDidChangeModel(e => this._update()));
39
+ this._update();
40
+ }
41
+ _update() {
42
+ this._keybindingDecorationRenderer.value = isInterestingEditorModel(this._editor, this._userDataProfileService)
43
+ ? this._instantiationService.createInstance(KeybindingEditorDecorationsRenderer, this._editor)
44
+ : undefined;
45
+ }
46
+ showDefineKeybindingWidget() {
47
+ if (isInterestingEditorModel(this._editor, this._userDataProfileService)) {
48
+ this._defineWidget.start().then(keybinding => this._onAccepted(keybinding));
49
+ }
50
+ }
51
+ _onAccepted(keybinding) {
52
+ this._editor.focus();
53
+ if (keybinding && this._editor.hasModel()) {
54
+ const regexp = ( new RegExp(/\\/g));
55
+ const backslash = regexp.test(keybinding);
56
+ if (backslash) {
57
+ keybinding = keybinding.slice(0, -1) + '\\\\';
58
+ }
59
+ let snippetText = [
60
+ '{',
61
+ '\t"key": ' + JSON.stringify(keybinding) + ',',
62
+ '\t"command": "${1:commandId}",',
63
+ '\t"when": "${2:editorTextFocus}"',
64
+ '}$0'
65
+ ].join('\n');
66
+ const smartInsertInfo = SmartSnippetInserter.insertSnippet(this._editor.getModel(), this._editor.getPosition());
67
+ snippetText = smartInsertInfo.prepend + snippetText + smartInsertInfo.append;
68
+ this._editor.setPosition(smartInsertInfo.position);
69
+ SnippetController2.get(this._editor)?.insert(snippetText, { overwriteBefore: 0, overwriteAfter: 0 });
70
+ }
71
+ }
72
+ };
73
+ DefineKeybindingEditorContribution = ( __decorate([
74
+ ( __param(1, IInstantiationService)),
75
+ ( __param(2, IUserDataProfileService))
76
+ ], DefineKeybindingEditorContribution));
77
+ let KeybindingEditorDecorationsRenderer = KeybindingEditorDecorationsRenderer_1 = class KeybindingEditorDecorationsRenderer extends Disposable {
78
+ constructor(_editor, _keybindingService) {
79
+ super();
80
+ this._editor = _editor;
81
+ this._keybindingService = _keybindingService;
82
+ this._dec = this._editor.createDecorationsCollection();
83
+ this._updateDecorations = this._register(( new RunOnceScheduler(() => this._updateDecorationsNow(), 500)));
84
+ const model = assertIsDefined(this._editor.getModel());
85
+ this._register(model.onDidChangeContent(() => this._updateDecorations.schedule()));
86
+ this._register(this._keybindingService.onDidUpdateKeybindings(() => this._updateDecorations.schedule()));
87
+ this._register({
88
+ dispose: () => {
89
+ this._dec.clear();
90
+ this._updateDecorations.cancel();
91
+ }
92
+ });
93
+ this._updateDecorations.schedule();
94
+ }
95
+ _updateDecorationsNow() {
96
+ const model = assertIsDefined(this._editor.getModel());
97
+ const newDecorations = [];
98
+ const root = parseTree(model.getValue());
99
+ if (root && Array.isArray(root.children)) {
100
+ for (let i = 0, len = root.children.length; i < len; i++) {
101
+ const entry = root.children[i];
102
+ const dec = this._getDecorationForEntry(model, entry);
103
+ if (dec !== null) {
104
+ newDecorations.push(dec);
105
+ }
106
+ }
107
+ }
108
+ this._dec.set(newDecorations);
109
+ }
110
+ _getDecorationForEntry(model, entry) {
111
+ if (!Array.isArray(entry.children)) {
112
+ return null;
113
+ }
114
+ for (let i = 0, len = entry.children.length; i < len; i++) {
115
+ const prop = entry.children[i];
116
+ if (prop.type !== 'property') {
117
+ continue;
118
+ }
119
+ if (!Array.isArray(prop.children) || prop.children.length !== 2) {
120
+ continue;
121
+ }
122
+ const key = prop.children[0];
123
+ if (key.value !== 'key') {
124
+ continue;
125
+ }
126
+ const value = prop.children[1];
127
+ if (value.type !== 'string') {
128
+ continue;
129
+ }
130
+ const resolvedKeybindings = this._keybindingService.resolveUserBinding(value.value);
131
+ if (resolvedKeybindings.length === 0) {
132
+ return this._createDecoration(true, null, null, model, value);
133
+ }
134
+ const resolvedKeybinding = resolvedKeybindings[0];
135
+ let usLabel = null;
136
+ if (resolvedKeybinding instanceof WindowsNativeResolvedKeybinding) {
137
+ usLabel = resolvedKeybinding.getUSLabel();
138
+ }
139
+ if (!resolvedKeybinding.isWYSIWYG()) {
140
+ const uiLabel = resolvedKeybinding.getLabel();
141
+ if (typeof uiLabel === 'string' && value.value.toLowerCase() === uiLabel.toLowerCase()) {
142
+ return null;
143
+ }
144
+ return this._createDecoration(false, resolvedKeybinding.getLabel(), usLabel, model, value);
145
+ }
146
+ if (/abnt_|oem_/.test(value.value)) {
147
+ return this._createDecoration(false, resolvedKeybinding.getLabel(), usLabel, model, value);
148
+ }
149
+ const expectedUserSettingsLabel = resolvedKeybinding.getUserSettingsLabel();
150
+ if (typeof expectedUserSettingsLabel === 'string' && !KeybindingEditorDecorationsRenderer_1._userSettingsFuzzyEquals(value.value, expectedUserSettingsLabel)) {
151
+ return this._createDecoration(false, resolvedKeybinding.getLabel(), usLabel, model, value);
152
+ }
153
+ return null;
154
+ }
155
+ return null;
156
+ }
157
+ static _userSettingsFuzzyEquals(a, b) {
158
+ a = a.trim().toLowerCase();
159
+ b = b.trim().toLowerCase();
160
+ if (a === b) {
161
+ return true;
162
+ }
163
+ const aKeybinding = KeybindingParser.parseKeybinding(a);
164
+ const bKeybinding = KeybindingParser.parseKeybinding(b);
165
+ if (aKeybinding === null && bKeybinding === null) {
166
+ return true;
167
+ }
168
+ if (!aKeybinding || !bKeybinding) {
169
+ return false;
170
+ }
171
+ return aKeybinding.equals(bKeybinding);
172
+ }
173
+ _createDecoration(isError, uiLabel, usLabel, model, keyNode) {
174
+ let msg;
175
+ let className;
176
+ let overviewRulerColor;
177
+ if (isError) {
178
+ msg = ( new MarkdownString()).appendText(NLS_KB_LAYOUT_ERROR_MESSAGE);
179
+ className = 'keybindingError';
180
+ overviewRulerColor = themeColorFromId(overviewRulerError);
181
+ }
182
+ else {
183
+ if (usLabel && uiLabel !== usLabel) {
184
+ msg = ( new MarkdownString(( localizeWithPath(
185
+ 'vs/workbench/contrib/preferences/browser/keybindingsEditorContribution',
186
+ {
187
+ key: 'defineKeybinding.kbLayoutLocalAndUSMessage',
188
+ comment: [
189
+ 'Please translate maintaining the stars (*) around the placeholders such that they will be rendered in bold.',
190
+ 'The placeholders will contain a keyboard combination e.g. Ctrl+Shift+/'
191
+ ]
192
+ },
193
+ "**{0}** for your current keyboard layout (**{1}** for US standard).",
194
+ uiLabel,
195
+ usLabel
196
+ ))));
197
+ }
198
+ else {
199
+ msg = ( new MarkdownString(( localizeWithPath(
200
+ 'vs/workbench/contrib/preferences/browser/keybindingsEditorContribution',
201
+ {
202
+ key: 'defineKeybinding.kbLayoutLocalMessage',
203
+ comment: [
204
+ 'Please translate maintaining the stars (*) around the placeholder such that it will be rendered in bold.',
205
+ 'The placeholder will contain a keyboard combination e.g. Ctrl+Shift+/'
206
+ ]
207
+ },
208
+ "**{0}** for your current keyboard layout.",
209
+ uiLabel
210
+ ))));
211
+ }
212
+ className = 'keybindingInfo';
213
+ overviewRulerColor = themeColorFromId(overviewRulerInfo);
214
+ }
215
+ const startPosition = model.getPositionAt(keyNode.offset);
216
+ const endPosition = model.getPositionAt(keyNode.offset + keyNode.length);
217
+ const range = ( new Range(
218
+ startPosition.lineNumber,
219
+ startPosition.column,
220
+ endPosition.lineNumber,
221
+ endPosition.column
222
+ ));
223
+ return {
224
+ range: range,
225
+ options: {
226
+ description: 'keybindings-widget',
227
+ stickiness: 1 ,
228
+ className: className,
229
+ hoverMessage: msg,
230
+ overviewRuler: {
231
+ color: overviewRulerColor,
232
+ position: OverviewRulerLane.Right
233
+ }
234
+ }
235
+ };
236
+ }
237
+ };
238
+ KeybindingEditorDecorationsRenderer = KeybindingEditorDecorationsRenderer_1 = ( __decorate([
239
+ ( __param(1, IKeybindingService))
240
+ ], KeybindingEditorDecorationsRenderer));
241
+ function isInterestingEditorModel(editor, userDataProfileService) {
242
+ const model = editor.getModel();
243
+ if (!model) {
244
+ return false;
245
+ }
246
+ return isEqual(model.uri, userDataProfileService.currentProfile.keybindingsResource);
247
+ }
248
+ registerEditorContribution(DEFINE_KEYBINDING_EDITOR_CONTRIB_ID, DefineKeybindingEditorContribution, 1 );
249
+
250
+ export { KeybindingEditorDecorationsRenderer };