@theia/monaco 1.53.0-next.55 → 1.53.0-next.64

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 (77) hide show
  1. package/README.md +100 -100
  2. package/data/monaco-nls.json +1379 -1379
  3. package/data/monaco-themes/vscode/dark_plus.json +201 -201
  4. package/data/monaco-themes/vscode/dark_theia.json +5 -5
  5. package/data/monaco-themes/vscode/dark_vs.json +393 -393
  6. package/data/monaco-themes/vscode/hc_black.json +457 -457
  7. package/data/monaco-themes/vscode/hc_light.json +590 -590
  8. package/data/monaco-themes/vscode/hc_theia.json +5 -5
  9. package/data/monaco-themes/vscode/hc_theia_light.json +5 -5
  10. package/data/monaco-themes/vscode/light_plus.json +202 -202
  11. package/data/monaco-themes/vscode/light_theia.json +10 -10
  12. package/data/monaco-themes/vscode/light_vs.json +421 -421
  13. package/lib/browser/monaco-editor-zone-widget.js +1 -1
  14. package/lib/browser/monaco-frontend-application-contribution.js +25 -25
  15. package/lib/browser/simple-monaco-editor.d.ts +3 -1
  16. package/lib/browser/simple-monaco-editor.d.ts.map +1 -1
  17. package/lib/browser/simple-monaco-editor.js +9 -2
  18. package/lib/browser/simple-monaco-editor.js.map +1 -1
  19. package/package.json +8 -8
  20. package/src/browser/index.ts +17 -17
  21. package/src/browser/markdown-renderer/monaco-markdown-renderer.ts +109 -109
  22. package/src/browser/monaco-bulk-edit-service.ts +64 -64
  23. package/src/browser/monaco-color-registry.ts +73 -73
  24. package/src/browser/monaco-command-registry.ts +85 -85
  25. package/src/browser/monaco-command-service.ts +90 -90
  26. package/src/browser/monaco-command.ts +303 -303
  27. package/src/browser/monaco-context-key-service.ts +144 -144
  28. package/src/browser/monaco-context-menu.ts +112 -112
  29. package/src/browser/monaco-diff-editor.ts +141 -141
  30. package/src/browser/monaco-diff-navigator-factory.ts +39 -39
  31. package/src/browser/monaco-editor-model.ts +693 -693
  32. package/src/browser/monaco-editor-peek-view-widget.ts +233 -233
  33. package/src/browser/monaco-editor-provider.ts +455 -455
  34. package/src/browser/monaco-editor-service.ts +152 -152
  35. package/src/browser/monaco-editor-zone-widget.ts +250 -250
  36. package/src/browser/monaco-editor.ts +733 -733
  37. package/src/browser/monaco-formatting-conflicts.ts +116 -116
  38. package/src/browser/monaco-frontend-application-contribution.ts +182 -182
  39. package/src/browser/monaco-frontend-module.ts +319 -319
  40. package/src/browser/monaco-gotoline-quick-access.ts +47 -47
  41. package/src/browser/monaco-gotosymbol-quick-access.ts +53 -53
  42. package/src/browser/monaco-icon-registry.ts +49 -49
  43. package/src/browser/monaco-indexed-db.ts +130 -130
  44. package/src/browser/monaco-init.ts +134 -134
  45. package/src/browser/monaco-keybinding.ts +111 -111
  46. package/src/browser/monaco-keycode-map.ts +171 -171
  47. package/src/browser/monaco-languages.ts +177 -177
  48. package/src/browser/monaco-marker-collection.ts +83 -83
  49. package/src/browser/monaco-menu.ts +147 -147
  50. package/src/browser/monaco-mime-service.ts +71 -71
  51. package/src/browser/monaco-outline-contribution.ts +404 -404
  52. package/src/browser/monaco-outline-decorator.ts +66 -66
  53. package/src/browser/monaco-quick-access-registry.ts +112 -112
  54. package/src/browser/monaco-quick-input-service.ts +701 -701
  55. package/src/browser/monaco-resolved-keybinding.ts +162 -162
  56. package/src/browser/monaco-snippet-suggest-provider.ts +306 -306
  57. package/src/browser/monaco-standalone-theme-service.ts +51 -51
  58. package/src/browser/monaco-status-bar-contribution.ts +110 -110
  59. package/src/browser/monaco-text-model-service.ts +157 -157
  60. package/src/browser/monaco-theming-service.ts +204 -204
  61. package/src/browser/monaco-to-protocol-converter.ts +82 -82
  62. package/src/browser/monaco-undo-redo-handler.ts +64 -64
  63. package/src/browser/monaco-workspace.ts +416 -416
  64. package/src/browser/protocol-to-monaco-converter.ts +158 -158
  65. package/src/browser/simple-monaco-editor.ts +228 -216
  66. package/src/browser/style/index.css +266 -266
  67. package/src/browser/textmate/index.ts +20 -20
  68. package/src/browser/textmate/monaco-textmate-frontend-bindings.ts +90 -90
  69. package/src/browser/textmate/monaco-textmate-service.ts +187 -187
  70. package/src/browser/textmate/monaco-theme-registry.ts +176 -176
  71. package/src/browser/textmate/monaco-theme-types.ts +37 -37
  72. package/src/browser/textmate/textmate-contribution.ts +29 -29
  73. package/src/browser/textmate/textmate-registry.ts +129 -129
  74. package/src/browser/textmate/textmate-snippet-completion-provider.ts +73 -73
  75. package/src/browser/textmate/textmate-tokenizer.ts +84 -84
  76. package/src/browser/workspace-symbol-command.ts +196 -196
  77. package/src/package.spec.ts +28 -28
@@ -1,134 +1,134 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 STMicroelectronics and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /*
18
- * The code in this file is responsible for overriding service implementations in the Monaco editor with our own Theia-based implementations.
19
- * Since we only get a single chance to call `StandaloneServies.initialize()` with our overrides, we need to make sure that intialize is called before the first call to
20
- * `StandaloneServices.get()` or `StandaloneServies.initialize()`. As we do not control the mechanics of Inversify instance constructions, the approach here is to call
21
- * `MonacoInit.init()` from the `index.js` file after all container modules are loaded, but before the first object is fetched from it.
22
- * `StandaloneServices.initialize()` is called with service descriptors, not service instances. This lets us finish all overrides before any inversify object is constructed and
23
- * might call `initialize()` while being constructed.
24
- * The service descriptors require a constructor function, so we declare dummy class for each Monaco service we override. But instead of returning an instance of the dummy class,
25
- * we fetch the implementation of the monaco service from the inversify container.
26
- * The inversify-constructed services must not call StandaloneServices.get() or StandaloneServices.initialize() from their constructors. Calling `get`()` in postConstruct mehtods
27
- * is allowed.
28
- */
29
-
30
- // Before importing anything from monaco we need to override its localization function
31
- import * as MonacoNls from '@theia/monaco-editor-core/esm/vs/nls';
32
- import { nls } from '@theia/core/lib/common/nls';
33
- import { FormatType, Localization } from '@theia/core/lib/common/i18n/localization';
34
-
35
- Object.assign(MonacoNls, {
36
- localize(_key: string, label: string, ...args: FormatType[]): string {
37
- if (nls.locale) {
38
- const defaultKey = nls.getDefaultKey(label);
39
- if (defaultKey) {
40
- return nls.localize(defaultKey, label, ...args);
41
- }
42
- }
43
- return Localization.format(label, args);
44
- }
45
- });
46
-
47
- import { Container } from '@theia/core/shared/inversify';
48
- import { ICodeEditorService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/codeEditorService';
49
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
50
- import { SyncDescriptor } from '@theia/monaco-editor-core/esm/vs/platform/instantiation/common/descriptors';
51
- import { MonacoEditorServiceFactory, MonacoEditorServiceFactoryType } from './monaco-editor-service';
52
- import { IConfigurationService } from '@theia/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
53
- import { ITextModelService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
54
- import { MonacoConfigurationService } from './monaco-frontend-module';
55
- import { MonacoTextModelService } from './monaco-text-model-service';
56
- import { MonacoContextMenuService } from './monaco-context-menu';
57
- import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView';
58
- import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
59
- import { IThemeService } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
60
- import { MonacoBulkEditService } from './monaco-bulk-edit-service';
61
- import { MonacoCommandService } from './monaco-command-service';
62
- import { IBulkEditService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/bulkEditService';
63
- import { ICommandService } from '@theia/monaco-editor-core/esm/vs/platform/commands/common/commands';
64
- import { MonacoQuickInputImplementation } from './monaco-quick-input-service';
65
- import { IQuickInputService } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/common/quickInput';
66
- import { IStandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/common/standaloneTheme';
67
- import { MonacoStandaloneThemeService } from './monaco-standalone-theme-service';
68
-
69
- class MonacoEditorServiceConstructor {
70
- /**
71
- * MonacoEditorService needs other Monaco services as constructor parameters, so we need to do use a factory for constructing the service. If we want the singleton instance,
72
- * we need to fetch it from the `StandaloneServices` class instead of injecting it.
73
- * @param container
74
- * @param contextKeyService
75
- * @param themeService
76
- */
77
- constructor(container: Container,
78
- @IContextKeyService contextKeyService: IContextKeyService,
79
- @IThemeService themeService: IThemeService) {
80
-
81
- return container.get<MonacoEditorServiceFactoryType>(MonacoEditorServiceFactory)(contextKeyService, themeService);
82
- };
83
- }
84
-
85
- class MonacoConfigurationServiceConstructor {
86
- constructor(container: Container) {
87
- return container.get(MonacoConfigurationService);
88
- }
89
- }
90
-
91
- class MonacoTextModelServiceConstructor {
92
- constructor(container: Container) {
93
- return container.get(MonacoTextModelService);
94
- }
95
- }
96
-
97
- class MonacoContextMenuServiceConstructor {
98
- constructor(container: Container) {
99
- return container.get(MonacoContextMenuService);
100
- }
101
- }
102
-
103
- class MonacoBulkEditServiceConstructor {
104
- constructor(container: Container) {
105
- return container.get(MonacoBulkEditService);
106
- }
107
- }
108
-
109
- class MonacoCommandServiceConstructor {
110
- constructor(container: Container) {
111
- return container.get(MonacoCommandService);
112
- }
113
- }
114
-
115
- class MonacoQuickInputImplementationConstructor {
116
- constructor(container: Container) {
117
- return container.get(MonacoQuickInputImplementation);
118
- }
119
- }
120
-
121
- export namespace MonacoInit {
122
- export function init(container: Container): void {
123
- StandaloneServices.initialize({
124
- [ICodeEditorService.toString()]: new SyncDescriptor(MonacoEditorServiceConstructor, [container]),
125
- [IConfigurationService.toString()]: new SyncDescriptor(MonacoConfigurationServiceConstructor, [container]),
126
- [ITextModelService.toString()]: new SyncDescriptor(MonacoTextModelServiceConstructor, [container]),
127
- [IContextMenuService.toString()]: new SyncDescriptor(MonacoContextMenuServiceConstructor, [container]),
128
- [IBulkEditService.toString()]: new SyncDescriptor(MonacoBulkEditServiceConstructor, [container]),
129
- [ICommandService.toString()]: new SyncDescriptor(MonacoCommandServiceConstructor, [container]),
130
- [IQuickInputService.toString()]: new SyncDescriptor(MonacoQuickInputImplementationConstructor, [container]),
131
- [IStandaloneThemeService.toString()]: new MonacoStandaloneThemeService()
132
- });
133
- }
134
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /*
18
+ * The code in this file is responsible for overriding service implementations in the Monaco editor with our own Theia-based implementations.
19
+ * Since we only get a single chance to call `StandaloneServies.initialize()` with our overrides, we need to make sure that intialize is called before the first call to
20
+ * `StandaloneServices.get()` or `StandaloneServies.initialize()`. As we do not control the mechanics of Inversify instance constructions, the approach here is to call
21
+ * `MonacoInit.init()` from the `index.js` file after all container modules are loaded, but before the first object is fetched from it.
22
+ * `StandaloneServices.initialize()` is called with service descriptors, not service instances. This lets us finish all overrides before any inversify object is constructed and
23
+ * might call `initialize()` while being constructed.
24
+ * The service descriptors require a constructor function, so we declare dummy class for each Monaco service we override. But instead of returning an instance of the dummy class,
25
+ * we fetch the implementation of the monaco service from the inversify container.
26
+ * The inversify-constructed services must not call StandaloneServices.get() or StandaloneServices.initialize() from their constructors. Calling `get`()` in postConstruct mehtods
27
+ * is allowed.
28
+ */
29
+
30
+ // Before importing anything from monaco we need to override its localization function
31
+ import * as MonacoNls from '@theia/monaco-editor-core/esm/vs/nls';
32
+ import { nls } from '@theia/core/lib/common/nls';
33
+ import { FormatType, Localization } from '@theia/core/lib/common/i18n/localization';
34
+
35
+ Object.assign(MonacoNls, {
36
+ localize(_key: string, label: string, ...args: FormatType[]): string {
37
+ if (nls.locale) {
38
+ const defaultKey = nls.getDefaultKey(label);
39
+ if (defaultKey) {
40
+ return nls.localize(defaultKey, label, ...args);
41
+ }
42
+ }
43
+ return Localization.format(label, args);
44
+ }
45
+ });
46
+
47
+ import { Container } from '@theia/core/shared/inversify';
48
+ import { ICodeEditorService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/codeEditorService';
49
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
50
+ import { SyncDescriptor } from '@theia/monaco-editor-core/esm/vs/platform/instantiation/common/descriptors';
51
+ import { MonacoEditorServiceFactory, MonacoEditorServiceFactoryType } from './monaco-editor-service';
52
+ import { IConfigurationService } from '@theia/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
53
+ import { ITextModelService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
54
+ import { MonacoConfigurationService } from './monaco-frontend-module';
55
+ import { MonacoTextModelService } from './monaco-text-model-service';
56
+ import { MonacoContextMenuService } from './monaco-context-menu';
57
+ import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView';
58
+ import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
59
+ import { IThemeService } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
60
+ import { MonacoBulkEditService } from './monaco-bulk-edit-service';
61
+ import { MonacoCommandService } from './monaco-command-service';
62
+ import { IBulkEditService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/bulkEditService';
63
+ import { ICommandService } from '@theia/monaco-editor-core/esm/vs/platform/commands/common/commands';
64
+ import { MonacoQuickInputImplementation } from './monaco-quick-input-service';
65
+ import { IQuickInputService } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/common/quickInput';
66
+ import { IStandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/common/standaloneTheme';
67
+ import { MonacoStandaloneThemeService } from './monaco-standalone-theme-service';
68
+
69
+ class MonacoEditorServiceConstructor {
70
+ /**
71
+ * MonacoEditorService needs other Monaco services as constructor parameters, so we need to do use a factory for constructing the service. If we want the singleton instance,
72
+ * we need to fetch it from the `StandaloneServices` class instead of injecting it.
73
+ * @param container
74
+ * @param contextKeyService
75
+ * @param themeService
76
+ */
77
+ constructor(container: Container,
78
+ @IContextKeyService contextKeyService: IContextKeyService,
79
+ @IThemeService themeService: IThemeService) {
80
+
81
+ return container.get<MonacoEditorServiceFactoryType>(MonacoEditorServiceFactory)(contextKeyService, themeService);
82
+ };
83
+ }
84
+
85
+ class MonacoConfigurationServiceConstructor {
86
+ constructor(container: Container) {
87
+ return container.get(MonacoConfigurationService);
88
+ }
89
+ }
90
+
91
+ class MonacoTextModelServiceConstructor {
92
+ constructor(container: Container) {
93
+ return container.get(MonacoTextModelService);
94
+ }
95
+ }
96
+
97
+ class MonacoContextMenuServiceConstructor {
98
+ constructor(container: Container) {
99
+ return container.get(MonacoContextMenuService);
100
+ }
101
+ }
102
+
103
+ class MonacoBulkEditServiceConstructor {
104
+ constructor(container: Container) {
105
+ return container.get(MonacoBulkEditService);
106
+ }
107
+ }
108
+
109
+ class MonacoCommandServiceConstructor {
110
+ constructor(container: Container) {
111
+ return container.get(MonacoCommandService);
112
+ }
113
+ }
114
+
115
+ class MonacoQuickInputImplementationConstructor {
116
+ constructor(container: Container) {
117
+ return container.get(MonacoQuickInputImplementation);
118
+ }
119
+ }
120
+
121
+ export namespace MonacoInit {
122
+ export function init(container: Container): void {
123
+ StandaloneServices.initialize({
124
+ [ICodeEditorService.toString()]: new SyncDescriptor(MonacoEditorServiceConstructor, [container]),
125
+ [IConfigurationService.toString()]: new SyncDescriptor(MonacoConfigurationServiceConstructor, [container]),
126
+ [ITextModelService.toString()]: new SyncDescriptor(MonacoTextModelServiceConstructor, [container]),
127
+ [IContextMenuService.toString()]: new SyncDescriptor(MonacoContextMenuServiceConstructor, [container]),
128
+ [IBulkEditService.toString()]: new SyncDescriptor(MonacoBulkEditServiceConstructor, [container]),
129
+ [ICommandService.toString()]: new SyncDescriptor(MonacoCommandServiceConstructor, [container]),
130
+ [IQuickInputService.toString()]: new SyncDescriptor(MonacoQuickInputImplementationConstructor, [container]),
131
+ [IStandaloneThemeService.toString()]: new MonacoStandaloneThemeService()
132
+ });
133
+ }
134
+ }
@@ -1,111 +1,111 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
18
- import { KeybindingContribution, KeybindingRegistry, KeybindingScope, KeyCode } from '@theia/core/lib/browser';
19
- import { MonacoCommands } from './monaco-command';
20
- import { MonacoCommandRegistry } from './monaco-command-registry';
21
- import { CommandRegistry, DisposableCollection, environment, isOSX } from '@theia/core';
22
- import { MonacoResolvedKeybinding } from './monaco-resolved-keybinding';
23
- import { KeybindingsRegistry } from '@theia/monaco-editor-core/esm/vs/platform/keybinding/common/keybindingsRegistry';
24
- import { StandaloneKeybindingService, StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
25
- import { IKeybindingService } from '@theia/monaco-editor-core/esm/vs/platform/keybinding/common/keybinding';
26
- import { MonacoContextKeyService } from './monaco-context-key-service';
27
- import { KEY_CODE_MAP } from './monaco-keycode-map';
28
- import * as monaco from '@theia/monaco-editor-core';
29
-
30
- @injectable()
31
- export class MonacoKeybindingContribution implements KeybindingContribution {
32
-
33
- protected toDisposeOnKeybindingChange = new DisposableCollection();
34
-
35
- @inject(MonacoCommandRegistry) protected readonly commands: MonacoCommandRegistry;
36
- @inject(KeybindingRegistry) protected readonly keybindings: KeybindingRegistry;
37
- @inject(CommandRegistry) protected readonly theiaCommandRegistry: CommandRegistry;
38
- @inject(MonacoContextKeyService) protected readonly contextKeyService: MonacoContextKeyService;
39
-
40
- @postConstruct()
41
- protected init(): void {
42
- this.keybindings.onKeybindingsChanged(() => this.updateMonacoKeybindings());
43
- }
44
-
45
- registerKeybindings(registry: KeybindingRegistry): void {
46
- const defaultKeybindings = KeybindingsRegistry.getDefaultKeybindings();
47
- for (const item of defaultKeybindings) {
48
- const command = this.commands.validate(item.command || undefined);
49
- if (command && item.keybinding) {
50
- const when = (item.when && item.when.serialize()) ?? undefined;
51
- let keybinding;
52
- if (item.command === MonacoCommands.GO_TO_DEFINITION && !environment.electron.is()) {
53
- keybinding = 'ctrlcmd+f11';
54
- } else {
55
- keybinding = MonacoResolvedKeybinding.toKeybinding(item.keybinding.chords);
56
- }
57
- registry.registerKeybinding({ command, keybinding, when });
58
- }
59
- }
60
- }
61
-
62
- protected updateMonacoKeybindings(): void {
63
- const monacoKeybindingRegistry = StandaloneServices.get(IKeybindingService);
64
- if (monacoKeybindingRegistry instanceof StandaloneKeybindingService) {
65
- this.toDisposeOnKeybindingChange.dispose();
66
- for (const binding of this.keybindings.getKeybindingsByScope(KeybindingScope.USER).concat(this.keybindings.getKeybindingsByScope(KeybindingScope.WORKSPACE))) {
67
- const resolved = this.keybindings.resolveKeybinding(binding);
68
- const command = binding.command;
69
- const when = binding.when
70
- ? this.contextKeyService.parse(binding.when)
71
- : binding.context
72
- ? this.contextKeyService.parse(binding.context)
73
- : undefined;
74
- this.toDisposeOnKeybindingChange.push(monacoKeybindingRegistry.addDynamicKeybinding(
75
- binding.command,
76
- this.toMonacoKeybindingNumber(resolved),
77
- (_, ...args) => this.theiaCommandRegistry.executeCommand(command, ...args),
78
- when,
79
- ));
80
- }
81
- }
82
- }
83
-
84
- protected toMonacoKeybindingNumber(codes: KeyCode[]): number {
85
- const [firstPart, secondPart] = codes;
86
- if (codes.length > 2) {
87
- console.warn('Key chords should not consist of more than two parts; got ', codes);
88
- }
89
- const encodedFirstPart = this.toSingleMonacoKeybindingNumber(firstPart);
90
- const encodedSecondPart = secondPart ? this.toSingleMonacoKeybindingNumber(secondPart) << 16 : 0;
91
- return monaco.KeyMod.chord(encodedFirstPart, encodedSecondPart);
92
- }
93
-
94
- protected toSingleMonacoKeybindingNumber(code: KeyCode): number {
95
- const keyCode = code.key?.keyCode !== undefined ? KEY_CODE_MAP[code.key.keyCode] : 0;
96
- let encoded = (keyCode >>> 0) & 0x000000FF;
97
- if (code.alt) {
98
- encoded |= monaco.KeyMod.Alt;
99
- }
100
- if (code.shift) {
101
- encoded |= monaco.KeyMod.Shift;
102
- }
103
- if (code.ctrl) {
104
- encoded |= monaco.KeyMod.WinCtrl;
105
- }
106
- if (code.meta && isOSX) {
107
- encoded |= monaco.KeyMod.CtrlCmd;
108
- }
109
- return encoded;
110
- }
111
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
18
+ import { KeybindingContribution, KeybindingRegistry, KeybindingScope, KeyCode } from '@theia/core/lib/browser';
19
+ import { MonacoCommands } from './monaco-command';
20
+ import { MonacoCommandRegistry } from './monaco-command-registry';
21
+ import { CommandRegistry, DisposableCollection, environment, isOSX } from '@theia/core';
22
+ import { MonacoResolvedKeybinding } from './monaco-resolved-keybinding';
23
+ import { KeybindingsRegistry } from '@theia/monaco-editor-core/esm/vs/platform/keybinding/common/keybindingsRegistry';
24
+ import { StandaloneKeybindingService, StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
25
+ import { IKeybindingService } from '@theia/monaco-editor-core/esm/vs/platform/keybinding/common/keybinding';
26
+ import { MonacoContextKeyService } from './monaco-context-key-service';
27
+ import { KEY_CODE_MAP } from './monaco-keycode-map';
28
+ import * as monaco from '@theia/monaco-editor-core';
29
+
30
+ @injectable()
31
+ export class MonacoKeybindingContribution implements KeybindingContribution {
32
+
33
+ protected toDisposeOnKeybindingChange = new DisposableCollection();
34
+
35
+ @inject(MonacoCommandRegistry) protected readonly commands: MonacoCommandRegistry;
36
+ @inject(KeybindingRegistry) protected readonly keybindings: KeybindingRegistry;
37
+ @inject(CommandRegistry) protected readonly theiaCommandRegistry: CommandRegistry;
38
+ @inject(MonacoContextKeyService) protected readonly contextKeyService: MonacoContextKeyService;
39
+
40
+ @postConstruct()
41
+ protected init(): void {
42
+ this.keybindings.onKeybindingsChanged(() => this.updateMonacoKeybindings());
43
+ }
44
+
45
+ registerKeybindings(registry: KeybindingRegistry): void {
46
+ const defaultKeybindings = KeybindingsRegistry.getDefaultKeybindings();
47
+ for (const item of defaultKeybindings) {
48
+ const command = this.commands.validate(item.command || undefined);
49
+ if (command && item.keybinding) {
50
+ const when = (item.when && item.when.serialize()) ?? undefined;
51
+ let keybinding;
52
+ if (item.command === MonacoCommands.GO_TO_DEFINITION && !environment.electron.is()) {
53
+ keybinding = 'ctrlcmd+f11';
54
+ } else {
55
+ keybinding = MonacoResolvedKeybinding.toKeybinding(item.keybinding.chords);
56
+ }
57
+ registry.registerKeybinding({ command, keybinding, when });
58
+ }
59
+ }
60
+ }
61
+
62
+ protected updateMonacoKeybindings(): void {
63
+ const monacoKeybindingRegistry = StandaloneServices.get(IKeybindingService);
64
+ if (monacoKeybindingRegistry instanceof StandaloneKeybindingService) {
65
+ this.toDisposeOnKeybindingChange.dispose();
66
+ for (const binding of this.keybindings.getKeybindingsByScope(KeybindingScope.USER).concat(this.keybindings.getKeybindingsByScope(KeybindingScope.WORKSPACE))) {
67
+ const resolved = this.keybindings.resolveKeybinding(binding);
68
+ const command = binding.command;
69
+ const when = binding.when
70
+ ? this.contextKeyService.parse(binding.when)
71
+ : binding.context
72
+ ? this.contextKeyService.parse(binding.context)
73
+ : undefined;
74
+ this.toDisposeOnKeybindingChange.push(monacoKeybindingRegistry.addDynamicKeybinding(
75
+ binding.command,
76
+ this.toMonacoKeybindingNumber(resolved),
77
+ (_, ...args) => this.theiaCommandRegistry.executeCommand(command, ...args),
78
+ when,
79
+ ));
80
+ }
81
+ }
82
+ }
83
+
84
+ protected toMonacoKeybindingNumber(codes: KeyCode[]): number {
85
+ const [firstPart, secondPart] = codes;
86
+ if (codes.length > 2) {
87
+ console.warn('Key chords should not consist of more than two parts; got ', codes);
88
+ }
89
+ const encodedFirstPart = this.toSingleMonacoKeybindingNumber(firstPart);
90
+ const encodedSecondPart = secondPart ? this.toSingleMonacoKeybindingNumber(secondPart) << 16 : 0;
91
+ return monaco.KeyMod.chord(encodedFirstPart, encodedSecondPart);
92
+ }
93
+
94
+ protected toSingleMonacoKeybindingNumber(code: KeyCode): number {
95
+ const keyCode = code.key?.keyCode !== undefined ? KEY_CODE_MAP[code.key.keyCode] : 0;
96
+ let encoded = (keyCode >>> 0) & 0x000000FF;
97
+ if (code.alt) {
98
+ encoded |= monaco.KeyMod.Alt;
99
+ }
100
+ if (code.shift) {
101
+ encoded |= monaco.KeyMod.Shift;
102
+ }
103
+ if (code.ctrl) {
104
+ encoded |= monaco.KeyMod.WinCtrl;
105
+ }
106
+ if (code.meta && isOSX) {
107
+ encoded |= monaco.KeyMod.CtrlCmd;
108
+ }
109
+ return encoded;
110
+ }
111
+ }