@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,144 +1,144 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 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, postConstruct } from '@theia/core/shared/inversify';
18
- import {
19
- ContextKeyService as TheiaContextKeyService, ContextKey, ContextKeyChangeEvent,
20
- ScopedValueStore, ContextMatcher, ContextKeyValue
21
- } from '@theia/core/lib/browser/context-key-service';
22
- import { Emitter } from '@theia/core';
23
- import { AbstractContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
24
- import { ContextKeyExpr, ContextKeyExpression, IContext, IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
25
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
26
-
27
- @injectable()
28
- export class MonacoContextKeyService implements TheiaContextKeyService {
29
- protected readonly onDidChangeEmitter = new Emitter<ContextKeyChangeEvent>();
30
- readonly onDidChange = this.onDidChangeEmitter.event;
31
-
32
- get contextKeyService(): AbstractContextKeyService {
33
- return StandaloneServices.get(IContextKeyService) as AbstractContextKeyService;
34
- }
35
-
36
- @postConstruct()
37
- protected init(): void {
38
- this.contextKeyService.onDidChangeContext(e =>
39
- this.onDidChangeEmitter.fire({
40
- affects: keys => e.affectsSome(keys)
41
- })
42
- );
43
- }
44
-
45
- createKey<T extends ContextKeyValue>(key: string, defaultValue: T | undefined): ContextKey<T> {
46
- return this.contextKeyService.createKey(key, defaultValue);
47
- }
48
-
49
- activeContext?: HTMLElement | IContext;
50
-
51
- match(expression: string, context?: HTMLElement): boolean {
52
- const parsed = this.parse(expression);
53
- if (parsed) {
54
- const ctx = this.identifyContext(context);
55
- if (!ctx) {
56
- return this.contextKeyService.contextMatchesRules(parsed);
57
- }
58
- return parsed.evaluate(ctx);
59
- }
60
- return true;
61
- }
62
-
63
- protected identifyContext(callersContext?: HTMLElement | IContext, service: IContextKeyService = this.contextKeyService): IContext | undefined {
64
- if (callersContext && 'getValue' in callersContext) {
65
- return callersContext;
66
- } else if (this.activeContext && 'getValue' in this.activeContext) {
67
- return this.activeContext;
68
- }
69
- const browserContext = callersContext ?? this.activeContext ?? (document.activeElement instanceof HTMLElement ? document.activeElement : undefined);
70
- if (browserContext) {
71
- return service.getContext(browserContext);
72
- }
73
- return undefined;
74
- }
75
-
76
- protected readonly expressions = new Map<string, ContextKeyExpression>();
77
- parse(when: string): ContextKeyExpression | undefined {
78
- let expression = this.expressions.get(when);
79
- if (!expression) {
80
- expression = ContextKeyExpr.deserialize(when);
81
- if (expression) {
82
- this.expressions.set(when, expression);
83
- }
84
- }
85
- return expression;
86
- }
87
-
88
- parseKeys(expression: string): Set<string> | undefined {
89
- const expr = ContextKeyExpr.deserialize(expression);
90
- return expr ? new Set<string>(expr.keys()) : expr;
91
- }
92
-
93
- with<T>(values: Record<string, unknown>, callback: () => T): T {
94
- const oldActive = this.activeContext;
95
- const id = this.contextKeyService.createChildContext();
96
- const child = this.contextKeyService.getContextValuesContainer(id);
97
- for (const [key, value] of Object.entries(values)) {
98
- child.setValue(key, value);
99
- }
100
- this.activeContext = child;
101
- try {
102
- return callback();
103
- } finally {
104
- this.activeContext = oldActive;
105
- this.contextKeyService.disposeContext(id);
106
- }
107
- }
108
-
109
- createScoped(target: HTMLElement): ScopedValueStore {
110
- const scoped = this.contextKeyService.createScoped(target);
111
- if (scoped instanceof AbstractContextKeyService) {
112
- return scoped as AbstractContextKeyService & { createScoped(): ScopedValueStore };
113
- }
114
- return this;
115
- }
116
-
117
- createOverlay(overlay: Iterable<[string, unknown]>): ContextMatcher {
118
- const delegate = this.contextKeyService.createOverlay(overlay);
119
- return {
120
- match: (expression: string, context?: HTMLElement) => {
121
- const parsed = this.parse(expression);
122
- if (parsed) {
123
- const ctx = this.identifyContext(context, delegate);
124
- if (!ctx) {
125
- return delegate.contextMatchesRules(parsed);
126
- }
127
- return parsed.evaluate(ctx);
128
- }
129
- return true;
130
- }
131
- };
132
- }
133
-
134
- setContext(key: string, value: unknown): void {
135
- this.contextKeyService.setContext(key, value);
136
- }
137
-
138
- dispose(): void {
139
- this.activeContext = undefined;
140
- this.onDidChangeEmitter.dispose();
141
- this.contextKeyService.dispose();
142
- }
143
- }
144
-
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 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, postConstruct } from '@theia/core/shared/inversify';
18
+ import {
19
+ ContextKeyService as TheiaContextKeyService, ContextKey, ContextKeyChangeEvent,
20
+ ScopedValueStore, ContextMatcher, ContextKeyValue
21
+ } from '@theia/core/lib/browser/context-key-service';
22
+ import { Emitter } from '@theia/core';
23
+ import { AbstractContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
24
+ import { ContextKeyExpr, ContextKeyExpression, IContext, IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
25
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
26
+
27
+ @injectable()
28
+ export class MonacoContextKeyService implements TheiaContextKeyService {
29
+ protected readonly onDidChangeEmitter = new Emitter<ContextKeyChangeEvent>();
30
+ readonly onDidChange = this.onDidChangeEmitter.event;
31
+
32
+ get contextKeyService(): AbstractContextKeyService {
33
+ return StandaloneServices.get(IContextKeyService) as AbstractContextKeyService;
34
+ }
35
+
36
+ @postConstruct()
37
+ protected init(): void {
38
+ this.contextKeyService.onDidChangeContext(e =>
39
+ this.onDidChangeEmitter.fire({
40
+ affects: keys => e.affectsSome(keys)
41
+ })
42
+ );
43
+ }
44
+
45
+ createKey<T extends ContextKeyValue>(key: string, defaultValue: T | undefined): ContextKey<T> {
46
+ return this.contextKeyService.createKey(key, defaultValue);
47
+ }
48
+
49
+ activeContext?: HTMLElement | IContext;
50
+
51
+ match(expression: string, context?: HTMLElement): boolean {
52
+ const parsed = this.parse(expression);
53
+ if (parsed) {
54
+ const ctx = this.identifyContext(context);
55
+ if (!ctx) {
56
+ return this.contextKeyService.contextMatchesRules(parsed);
57
+ }
58
+ return parsed.evaluate(ctx);
59
+ }
60
+ return true;
61
+ }
62
+
63
+ protected identifyContext(callersContext?: HTMLElement | IContext, service: IContextKeyService = this.contextKeyService): IContext | undefined {
64
+ if (callersContext && 'getValue' in callersContext) {
65
+ return callersContext;
66
+ } else if (this.activeContext && 'getValue' in this.activeContext) {
67
+ return this.activeContext;
68
+ }
69
+ const browserContext = callersContext ?? this.activeContext ?? (document.activeElement instanceof HTMLElement ? document.activeElement : undefined);
70
+ if (browserContext) {
71
+ return service.getContext(browserContext);
72
+ }
73
+ return undefined;
74
+ }
75
+
76
+ protected readonly expressions = new Map<string, ContextKeyExpression>();
77
+ parse(when: string): ContextKeyExpression | undefined {
78
+ let expression = this.expressions.get(when);
79
+ if (!expression) {
80
+ expression = ContextKeyExpr.deserialize(when);
81
+ if (expression) {
82
+ this.expressions.set(when, expression);
83
+ }
84
+ }
85
+ return expression;
86
+ }
87
+
88
+ parseKeys(expression: string): Set<string> | undefined {
89
+ const expr = ContextKeyExpr.deserialize(expression);
90
+ return expr ? new Set<string>(expr.keys()) : expr;
91
+ }
92
+
93
+ with<T>(values: Record<string, unknown>, callback: () => T): T {
94
+ const oldActive = this.activeContext;
95
+ const id = this.contextKeyService.createChildContext();
96
+ const child = this.contextKeyService.getContextValuesContainer(id);
97
+ for (const [key, value] of Object.entries(values)) {
98
+ child.setValue(key, value);
99
+ }
100
+ this.activeContext = child;
101
+ try {
102
+ return callback();
103
+ } finally {
104
+ this.activeContext = oldActive;
105
+ this.contextKeyService.disposeContext(id);
106
+ }
107
+ }
108
+
109
+ createScoped(target: HTMLElement): ScopedValueStore {
110
+ const scoped = this.contextKeyService.createScoped(target);
111
+ if (scoped instanceof AbstractContextKeyService) {
112
+ return scoped as unknown as ScopedValueStore;
113
+ }
114
+ throw new Error('Could not created scoped value store');
115
+ }
116
+
117
+ createOverlay(overlay: Iterable<[string, unknown]>): ContextMatcher {
118
+ const delegate = this.contextKeyService.createOverlay(overlay);
119
+ return {
120
+ match: (expression: string, context?: HTMLElement) => {
121
+ const parsed = this.parse(expression);
122
+ if (parsed) {
123
+ const ctx = this.identifyContext(context, delegate);
124
+ if (!ctx) {
125
+ return delegate.contextMatchesRules(parsed);
126
+ }
127
+ return parsed.evaluate(ctx);
128
+ }
129
+ return true;
130
+ }
131
+ };
132
+ }
133
+
134
+ setContext(key: string, value: unknown): void {
135
+ this.contextKeyService.setContext(key, value);
136
+ }
137
+
138
+ dispose(): void {
139
+ this.activeContext = undefined;
140
+ this.onDidChangeEmitter.dispose();
141
+ this.contextKeyService.dispose();
142
+ }
143
+ }
144
+
@@ -1,112 +1,112 @@
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 } from '@theia/core/shared/inversify';
18
- import { MenuPath } from '@theia/core/lib/common/menu';
19
- import { EDITOR_CONTEXT_MENU } from '@theia/editor/lib/browser';
20
- import { Anchor, ContextMenuRenderer, Coordinate } from '@theia/core/lib/browser';
21
- import { Menu } from '@theia/core/shared/@phosphor/widgets';
22
- import { CommandRegistry } from '@theia/core/shared/@phosphor/commands';
23
- import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView';
24
- import { IContextMenuDelegate } from '@theia/monaco-editor-core/esm/vs/base/browser/contextmenu';
25
- import { MenuItemAction } from '@theia/monaco-editor-core/esm/vs/platform/actions/common/actions';
26
- import { Event, Emitter } from '@theia/monaco-editor-core/esm/vs/base/common/event';
27
- import { StandardMouseEvent } from '@theia/monaco-editor-core/esm/vs/base/browser/mouseEvent';
28
-
29
- @injectable()
30
- export class MonacoContextMenuService implements IContextMenuService {
31
- declare readonly _serviceBrand: undefined;
32
-
33
- protected readonly onDidShowContextMenuEmitter = new Emitter<void>();
34
- get onDidShowContextMenu(): Event<void> {
35
- return this.onDidShowContextMenuEmitter.event;
36
- };
37
- protected readonly onDidHideContextMenuEmitter = new Emitter<void>();
38
- get onDidHideContextMenu(): Event<void> {
39
- return this.onDidShowContextMenuEmitter.event;
40
- };
41
-
42
- @inject(ContextMenuRenderer) protected readonly contextMenuRenderer: ContextMenuRenderer;
43
-
44
- toAnchor(anchor: HTMLElement | Coordinate | StandardMouseEvent): Anchor {
45
- if (anchor instanceof HTMLElement) {
46
- return { x: anchor.offsetLeft, y: anchor.offsetTop };
47
- } else if (anchor instanceof StandardMouseEvent) {
48
- return { x: anchor.posx, y: anchor.posy };
49
- } else {
50
- return anchor;
51
- }
52
- }
53
-
54
- private getContext(delegate: IContextMenuDelegate): HTMLElement | undefined {
55
- const anchor = delegate.getAnchor();
56
- if (anchor instanceof HTMLElement) {
57
- return anchor;
58
- } else if (anchor instanceof StandardMouseEvent) {
59
- return anchor.target;
60
- } else {
61
- return undefined;
62
- }
63
- }
64
- showContextMenu(delegate: IContextMenuDelegate): void {
65
- const anchor = this.toAnchor(delegate.getAnchor());
66
- const actions = delegate.getActions();
67
- const context = this.getContext(delegate);
68
- const onHide = () => {
69
- delegate.onHide?.(false);
70
- this.onDidHideContextMenuEmitter.fire();
71
- };
72
-
73
- // Actions for editor context menu come as 'MenuItemAction' items
74
- // In case of 'Quick Fix' actions come as 'CodeActionAction' items
75
- if (actions.length > 0 && actions[0] instanceof MenuItemAction) {
76
- this.contextMenuRenderer.render({
77
- context: context,
78
- menuPath: this.menuPath(),
79
- anchor,
80
- onHide
81
- });
82
- } else {
83
- const commands = new CommandRegistry();
84
- const menu = new Menu({
85
- commands
86
- });
87
-
88
- for (const action of actions) {
89
- const commandId = 'quickfix_' + actions.indexOf(action);
90
- commands.addCommand(commandId, {
91
- label: action.label,
92
- className: action.class,
93
- isToggled: () => Boolean(action.checked),
94
- isEnabled: () => action.enabled,
95
- execute: () => action.run()
96
- });
97
- menu.addItem({
98
- type: 'command',
99
- command: commandId
100
- });
101
- }
102
- menu.aboutToClose.connect(() => onHide());
103
- menu.open(anchor.x, anchor.y);
104
- }
105
- this.onDidShowContextMenuEmitter.fire();
106
- }
107
-
108
- protected menuPath(): MenuPath {
109
- return EDITOR_CONTEXT_MENU;
110
- }
111
-
112
- }
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 } from '@theia/core/shared/inversify';
18
+ import { MenuPath } from '@theia/core/lib/common/menu';
19
+ import { EDITOR_CONTEXT_MENU } from '@theia/editor/lib/browser';
20
+ import { Anchor, ContextMenuRenderer, Coordinate } from '@theia/core/lib/browser';
21
+ import { Menu } from '@theia/core/shared/@phosphor/widgets';
22
+ import { CommandRegistry } from '@theia/core/shared/@phosphor/commands';
23
+ import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView';
24
+ import { IContextMenuDelegate } from '@theia/monaco-editor-core/esm/vs/base/browser/contextmenu';
25
+ import { MenuItemAction } from '@theia/monaco-editor-core/esm/vs/platform/actions/common/actions';
26
+ import { Event, Emitter } from '@theia/monaco-editor-core/esm/vs/base/common/event';
27
+ import { StandardMouseEvent } from '@theia/monaco-editor-core/esm/vs/base/browser/mouseEvent';
28
+
29
+ @injectable()
30
+ export class MonacoContextMenuService implements IContextMenuService {
31
+ declare readonly _serviceBrand: undefined;
32
+
33
+ protected readonly onDidShowContextMenuEmitter = new Emitter<void>();
34
+ get onDidShowContextMenu(): Event<void> {
35
+ return this.onDidShowContextMenuEmitter.event;
36
+ };
37
+ protected readonly onDidHideContextMenuEmitter = new Emitter<void>();
38
+ get onDidHideContextMenu(): Event<void> {
39
+ return this.onDidShowContextMenuEmitter.event;
40
+ };
41
+
42
+ @inject(ContextMenuRenderer) protected readonly contextMenuRenderer: ContextMenuRenderer;
43
+
44
+ toAnchor(anchor: HTMLElement | Coordinate | StandardMouseEvent): Anchor {
45
+ if (anchor instanceof HTMLElement) {
46
+ return { x: anchor.offsetLeft, y: anchor.offsetTop };
47
+ } else if (anchor instanceof StandardMouseEvent) {
48
+ return { x: anchor.posx, y: anchor.posy };
49
+ } else {
50
+ return anchor;
51
+ }
52
+ }
53
+
54
+ private getContext(delegate: IContextMenuDelegate): HTMLElement | undefined {
55
+ const anchor = delegate.getAnchor();
56
+ if (anchor instanceof HTMLElement) {
57
+ return anchor;
58
+ } else if (anchor instanceof StandardMouseEvent) {
59
+ return anchor.target;
60
+ } else {
61
+ return undefined;
62
+ }
63
+ }
64
+ showContextMenu(delegate: IContextMenuDelegate): void {
65
+ const anchor = this.toAnchor(delegate.getAnchor());
66
+ const actions = delegate.getActions();
67
+ const context = this.getContext(delegate);
68
+ const onHide = () => {
69
+ delegate.onHide?.(false);
70
+ this.onDidHideContextMenuEmitter.fire();
71
+ };
72
+
73
+ // Actions for editor context menu come as 'MenuItemAction' items
74
+ // In case of 'Quick Fix' actions come as 'CodeActionAction' items
75
+ if (actions.length > 0 && actions[0] instanceof MenuItemAction) {
76
+ this.contextMenuRenderer.render({
77
+ context: context,
78
+ menuPath: this.menuPath(),
79
+ anchor,
80
+ onHide
81
+ });
82
+ } else {
83
+ const commands = new CommandRegistry();
84
+ const menu = new Menu({
85
+ commands
86
+ });
87
+
88
+ for (const action of actions) {
89
+ const commandId = 'quickfix_' + actions.indexOf(action);
90
+ commands.addCommand(commandId, {
91
+ label: action.label,
92
+ className: action.class,
93
+ isToggled: () => Boolean(action.checked),
94
+ isEnabled: () => action.enabled,
95
+ execute: () => action.run()
96
+ });
97
+ menu.addItem({
98
+ type: 'command',
99
+ command: commandId
100
+ });
101
+ }
102
+ menu.aboutToClose.connect(() => onHide());
103
+ menu.open(anchor.x, anchor.y);
104
+ }
105
+ this.onDidShowContextMenuEmitter.fire();
106
+ }
107
+
108
+ protected menuPath(): MenuPath {
109
+ return EDITOR_CONTEXT_MENU;
110
+ }
111
+
112
+ }