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

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 (96) 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-context-key-service.js +1 -1
  14. package/lib/browser/monaco-context-key-service.js.map +1 -1
  15. package/lib/browser/monaco-editor-model.d.ts +11 -5
  16. package/lib/browser/monaco-editor-model.d.ts.map +1 -1
  17. package/lib/browser/monaco-editor-model.js +2 -1
  18. package/lib/browser/monaco-editor-model.js.map +1 -1
  19. package/lib/browser/monaco-editor-service.js +1 -1
  20. package/lib/browser/monaco-editor-service.js.map +1 -1
  21. package/lib/browser/monaco-editor-zone-widget.js +1 -1
  22. package/lib/browser/monaco-editor.d.ts +5 -4
  23. package/lib/browser/monaco-editor.d.ts.map +1 -1
  24. package/lib/browser/monaco-editor.js +5 -2
  25. package/lib/browser/monaco-editor.js.map +1 -1
  26. package/lib/browser/monaco-frontend-application-contribution.js +25 -25
  27. package/lib/browser/monaco-quick-input-service.d.ts.map +1 -1
  28. package/lib/browser/monaco-quick-input-service.js +15 -15
  29. package/lib/browser/monaco-quick-input-service.js.map +1 -1
  30. package/lib/browser/monaco-text-model-service.d.ts +0 -10
  31. package/lib/browser/monaco-text-model-service.d.ts.map +1 -1
  32. package/lib/browser/monaco-text-model-service.js +0 -36
  33. package/lib/browser/monaco-text-model-service.js.map +1 -1
  34. package/lib/browser/monaco-to-protocol-converter.d.ts +2 -0
  35. package/lib/browser/monaco-to-protocol-converter.d.ts.map +1 -1
  36. package/lib/browser/monaco-to-protocol-converter.js +10 -0
  37. package/lib/browser/monaco-to-protocol-converter.js.map +1 -1
  38. package/package.json +9 -9
  39. package/src/browser/index.ts +17 -17
  40. package/src/browser/markdown-renderer/monaco-markdown-renderer.ts +109 -109
  41. package/src/browser/monaco-bulk-edit-service.ts +64 -64
  42. package/src/browser/monaco-color-registry.ts +73 -73
  43. package/src/browser/monaco-command-registry.ts +85 -85
  44. package/src/browser/monaco-command-service.ts +90 -90
  45. package/src/browser/monaco-command.ts +303 -303
  46. package/src/browser/monaco-context-key-service.ts +144 -144
  47. package/src/browser/monaco-context-menu.ts +112 -112
  48. package/src/browser/monaco-diff-editor.ts +141 -141
  49. package/src/browser/monaco-diff-navigator-factory.ts +39 -39
  50. package/src/browser/monaco-editor-model.ts +693 -685
  51. package/src/browser/monaco-editor-peek-view-widget.ts +233 -233
  52. package/src/browser/monaco-editor-provider.ts +455 -455
  53. package/src/browser/monaco-editor-service.ts +152 -152
  54. package/src/browser/monaco-editor-zone-widget.ts +250 -250
  55. package/src/browser/monaco-editor.ts +733 -729
  56. package/src/browser/monaco-formatting-conflicts.ts +116 -116
  57. package/src/browser/monaco-frontend-application-contribution.ts +182 -182
  58. package/src/browser/monaco-frontend-module.ts +319 -319
  59. package/src/browser/monaco-gotoline-quick-access.ts +47 -47
  60. package/src/browser/monaco-gotosymbol-quick-access.ts +53 -53
  61. package/src/browser/monaco-icon-registry.ts +49 -49
  62. package/src/browser/monaco-indexed-db.ts +130 -130
  63. package/src/browser/monaco-init.ts +134 -134
  64. package/src/browser/monaco-keybinding.ts +111 -111
  65. package/src/browser/monaco-keycode-map.ts +171 -171
  66. package/src/browser/monaco-languages.ts +177 -177
  67. package/src/browser/monaco-marker-collection.ts +83 -83
  68. package/src/browser/monaco-menu.ts +147 -147
  69. package/src/browser/monaco-mime-service.ts +71 -71
  70. package/src/browser/monaco-outline-contribution.ts +404 -404
  71. package/src/browser/monaco-outline-decorator.ts +66 -66
  72. package/src/browser/monaco-quick-access-registry.ts +112 -112
  73. package/src/browser/monaco-quick-input-service.ts +701 -702
  74. package/src/browser/monaco-resolved-keybinding.ts +162 -162
  75. package/src/browser/monaco-snippet-suggest-provider.ts +306 -306
  76. package/src/browser/monaco-standalone-theme-service.ts +51 -51
  77. package/src/browser/monaco-status-bar-contribution.ts +110 -110
  78. package/src/browser/monaco-text-model-service.ts +157 -199
  79. package/src/browser/monaco-theming-service.ts +204 -204
  80. package/src/browser/monaco-to-protocol-converter.ts +82 -71
  81. package/src/browser/monaco-undo-redo-handler.ts +64 -64
  82. package/src/browser/monaco-workspace.ts +416 -416
  83. package/src/browser/protocol-to-monaco-converter.ts +158 -158
  84. package/src/browser/simple-monaco-editor.ts +216 -216
  85. package/src/browser/style/index.css +266 -266
  86. package/src/browser/textmate/index.ts +20 -20
  87. package/src/browser/textmate/monaco-textmate-frontend-bindings.ts +90 -90
  88. package/src/browser/textmate/monaco-textmate-service.ts +187 -187
  89. package/src/browser/textmate/monaco-theme-registry.ts +176 -176
  90. package/src/browser/textmate/monaco-theme-types.ts +37 -37
  91. package/src/browser/textmate/textmate-contribution.ts +29 -29
  92. package/src/browser/textmate/textmate-registry.ts +129 -129
  93. package/src/browser/textmate/textmate-snippet-completion-provider.ts +73 -73
  94. package/src/browser/textmate/textmate-tokenizer.ts +84 -84
  95. package/src/browser/workspace-symbol-command.ts +196 -196
  96. 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
+ }