@theia/monaco 1.34.3 → 1.34.4

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 (170) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +100 -100
  3. package/data/monaco-nls.json +1379 -1379
  4. package/data/monaco-themes/vscode/dark_plus.json +201 -201
  5. package/data/monaco-themes/vscode/dark_theia.json +5 -5
  6. package/data/monaco-themes/vscode/dark_vs.json +392 -392
  7. package/data/monaco-themes/vscode/hc_black.json +457 -457
  8. package/data/monaco-themes/vscode/hc_light.json +590 -590
  9. package/data/monaco-themes/vscode/hc_theia.json +5 -5
  10. package/data/monaco-themes/vscode/hc_theia_light.json +5 -5
  11. package/data/monaco-themes/vscode/light_plus.json +202 -202
  12. package/data/monaco-themes/vscode/light_theia.json +10 -10
  13. package/data/monaco-themes/vscode/light_vs.json +421 -421
  14. package/lib/browser/index.d.ts +1 -1
  15. package/lib/browser/index.js +28 -28
  16. package/lib/browser/markdown-renderer/monaco-markdown-renderer.d.ts +24 -24
  17. package/lib/browser/markdown-renderer/monaco-markdown-renderer.js +137 -137
  18. package/lib/browser/monaco-bulk-edit-service.d.ts +14 -14
  19. package/lib/browser/monaco-bulk-edit-service.js +66 -66
  20. package/lib/browser/monaco-color-registry.d.ts +16 -16
  21. package/lib/browser/monaco-color-registry.js +82 -82
  22. package/lib/browser/monaco-command-registry.d.ts +19 -19
  23. package/lib/browser/monaco-command-registry.js +82 -82
  24. package/lib/browser/monaco-command-service.d.ts +26 -26
  25. package/lib/browser/monaco-command-service.js +92 -92
  26. package/lib/browser/monaco-command.d.ts +94 -94
  27. package/lib/browser/monaco-command.js +306 -306
  28. package/lib/browser/monaco-context-key-service.d.ts +22 -22
  29. package/lib/browser/monaco-context-key-service.js +147 -147
  30. package/lib/browser/monaco-context-menu.d.ts +16 -16
  31. package/lib/browser/monaco-context-menu.js +102 -102
  32. package/lib/browser/monaco-diagnostic-collection.d.ts +28 -28
  33. package/lib/browser/monaco-diagnostic-collection.js +86 -86
  34. package/lib/browser/monaco-diff-editor.d.ts +29 -29
  35. package/lib/browser/monaco-diff-editor.js +74 -74
  36. package/lib/browser/monaco-diff-navigator-factory.d.ts +7 -7
  37. package/lib/browser/monaco-diff-navigator-factory.js +66 -66
  38. package/lib/browser/monaco-editor-model.d.ts +156 -156
  39. package/lib/browser/monaco-editor-model.js +555 -555
  40. package/lib/browser/monaco-editor-provider.d.ts +89 -89
  41. package/lib/browser/monaco-editor-provider.js +440 -440
  42. package/lib/browser/monaco-editor-service.d.ts +27 -27
  43. package/lib/browser/monaco-editor-service.js +151 -151
  44. package/lib/browser/monaco-editor-zone-widget.d.ts +43 -43
  45. package/lib/browser/monaco-editor-zone-widget.js +194 -194
  46. package/lib/browser/monaco-editor.d.ts +151 -151
  47. package/lib/browser/monaco-editor.js +497 -497
  48. package/lib/browser/monaco-formatting-conflicts.d.ts +13 -13
  49. package/lib/browser/monaco-formatting-conflicts.js +110 -110
  50. package/lib/browser/monaco-frontend-application-contribution.d.ts +26 -26
  51. package/lib/browser/monaco-frontend-application-contribution.js +201 -201
  52. package/lib/browser/monaco-frontend-module.d.ts +7 -7
  53. package/lib/browser/monaco-frontend-module.js +266 -266
  54. package/lib/browser/monaco-gotoline-quick-access.d.ts +11 -11
  55. package/lib/browser/monaco-gotoline-quick-access.js +64 -64
  56. package/lib/browser/monaco-gotosymbol-quick-access.d.ts +16 -16
  57. package/lib/browser/monaco-gotosymbol-quick-access.js +70 -70
  58. package/lib/browser/monaco-indexed-db.d.ts +28 -28
  59. package/lib/browser/monaco-indexed-db.js +131 -131
  60. package/lib/browser/monaco-keybinding-contexts.d.ts +15 -15
  61. package/lib/browser/monaco-keybinding-contexts.js +50 -50
  62. package/lib/browser/monaco-keybinding.d.ts +16 -16
  63. package/lib/browser/monaco-keybinding.js +134 -134
  64. package/lib/browser/monaco-keycode-map.d.ts +2 -2
  65. package/lib/browser/monaco-keycode-map.js +163 -163
  66. package/lib/browser/monaco-languages.d.ts +27 -27
  67. package/lib/browser/monaco-languages.js +136 -136
  68. package/lib/browser/monaco-menu.d.ts +20 -20
  69. package/lib/browser/monaco-menu.js +145 -145
  70. package/lib/browser/monaco-mime-service.d.ts +10 -10
  71. package/lib/browser/monaco-mime-service.js +78 -78
  72. package/lib/browser/monaco-outline-contribution.d.ts +78 -78
  73. package/lib/browser/monaco-outline-contribution.js +384 -384
  74. package/lib/browser/monaco-outline-decorator.d.ts +12 -12
  75. package/lib/browser/monaco-outline-decorator.js +67 -67
  76. package/lib/browser/monaco-quick-access-registry.d.ts +11 -11
  77. package/lib/browser/monaco-quick-access-registry.js +99 -99
  78. package/lib/browser/monaco-quick-input-service.d.ts +99 -99
  79. package/lib/browser/monaco-quick-input-service.js +555 -555
  80. package/lib/browser/monaco-resolved-keybinding.d.ts +23 -23
  81. package/lib/browser/monaco-resolved-keybinding.js +131 -131
  82. package/lib/browser/monaco-snippet-suggest-provider.d.ts +64 -64
  83. package/lib/browser/monaco-snippet-suggest-provider.js +269 -269
  84. package/lib/browser/monaco-status-bar-contribution.d.ts +17 -17
  85. package/lib/browser/monaco-status-bar-contribution.js +120 -120
  86. package/lib/browser/monaco-text-model-service.d.ts +51 -51
  87. package/lib/browser/monaco-text-model-service.js +184 -184
  88. package/lib/browser/monaco-theming-service.d.ts +67 -67
  89. package/lib/browser/monaco-theming-service.js +171 -171
  90. package/lib/browser/monaco-to-protocol-converter.d.ts +26 -26
  91. package/lib/browser/monaco-to-protocol-converter.js +61 -61
  92. package/lib/browser/monaco-workspace.d.ts +83 -83
  93. package/lib/browser/monaco-workspace.js +369 -369
  94. package/lib/browser/protocol-to-monaco-converter.d.ts +31 -31
  95. package/lib/browser/protocol-to-monaco-converter.js +133 -133
  96. package/lib/browser/textmate/index.d.ts +4 -4
  97. package/lib/browser/textmate/index.js +31 -31
  98. package/lib/browser/textmate/monaco-textmate-frontend-bindings.d.ts +12 -12
  99. package/lib/browser/textmate/monaco-textmate-frontend-bindings.js +94 -94
  100. package/lib/browser/textmate/monaco-textmate-service.d.ts +30 -30
  101. package/lib/browser/textmate/monaco-textmate-service.js +185 -185
  102. package/lib/browser/textmate/monaco-theme-registry.d.ts +27 -27
  103. package/lib/browser/textmate/monaco-theme-registry.js +171 -171
  104. package/lib/browser/textmate/monaco-theme-types.d.ts +20 -20
  105. package/lib/browser/textmate/monaco-theme-types.js +21 -21
  106. package/lib/browser/textmate/textmate-contribution.d.ts +9 -9
  107. package/lib/browser/textmate/textmate-contribution.js +27 -27
  108. package/lib/browser/textmate/textmate-registry.d.ts +31 -31
  109. package/lib/browser/textmate/textmate-registry.js +109 -109
  110. package/lib/browser/textmate/textmate-snippet-completion-provider.d.ts +26 -26
  111. package/lib/browser/textmate/textmate-snippet-completion-provider.js +53 -53
  112. package/lib/browser/textmate/textmate-tokenizer.d.ts +22 -22
  113. package/lib/browser/textmate/textmate-tokenizer.js +65 -65
  114. package/lib/browser/workspace-symbol-command.d.ts +55 -55
  115. package/lib/browser/workspace-symbol-command.js +215 -215
  116. package/lib/package.spec.js +25 -25
  117. package/package.json +8 -8
  118. package/src/browser/index.ts +17 -17
  119. package/src/browser/markdown-renderer/monaco-markdown-renderer.ts +117 -117
  120. package/src/browser/monaco-bulk-edit-service.ts +64 -64
  121. package/src/browser/monaco-color-registry.ts +73 -73
  122. package/src/browser/monaco-command-registry.ts +82 -82
  123. package/src/browser/monaco-command-service.ts +99 -99
  124. package/src/browser/monaco-command.ts +311 -311
  125. package/src/browser/monaco-context-key-service.ts +143 -143
  126. package/src/browser/monaco-context-menu.ts +90 -90
  127. package/src/browser/monaco-diagnostic-collection.ts +101 -101
  128. package/src/browser/monaco-diff-editor.ts +101 -101
  129. package/src/browser/monaco-diff-navigator-factory.ts +61 -61
  130. package/src/browser/monaco-editor-model.ts +681 -681
  131. package/src/browser/monaco-editor-provider.ts +452 -452
  132. package/src/browser/monaco-editor-service.ts +144 -144
  133. package/src/browser/monaco-editor-zone-widget.ts +250 -250
  134. package/src/browser/monaco-editor.ts +644 -644
  135. package/src/browser/monaco-formatting-conflicts.ts +115 -115
  136. package/src/browser/monaco-frontend-application-contribution.ts +188 -188
  137. package/src/browser/monaco-frontend-module.ts +314 -314
  138. package/src/browser/monaco-gotoline-quick-access.ts +47 -47
  139. package/src/browser/monaco-gotosymbol-quick-access.ts +53 -53
  140. package/src/browser/monaco-indexed-db.ts +130 -130
  141. package/src/browser/monaco-keybinding-contexts.ts +43 -43
  142. package/src/browser/monaco-keybinding.ts +111 -111
  143. package/src/browser/monaco-keycode-map.ts +171 -171
  144. package/src/browser/monaco-languages.ts +129 -129
  145. package/src/browser/monaco-menu.ts +142 -142
  146. package/src/browser/monaco-mime-service.ts +71 -71
  147. package/src/browser/monaco-outline-contribution.ts +404 -404
  148. package/src/browser/monaco-outline-decorator.ts +66 -66
  149. package/src/browser/monaco-quick-access-registry.ts +112 -112
  150. package/src/browser/monaco-quick-input-service.ts +651 -651
  151. package/src/browser/monaco-resolved-keybinding.ts +162 -162
  152. package/src/browser/monaco-snippet-suggest-provider.ts +300 -300
  153. package/src/browser/monaco-status-bar-contribution.ts +109 -109
  154. package/src/browser/monaco-text-model-service.ts +194 -194
  155. package/src/browser/monaco-theming-service.ts +204 -204
  156. package/src/browser/monaco-to-protocol-converter.ts +71 -71
  157. package/src/browser/monaco-workspace.ts +393 -393
  158. package/src/browser/protocol-to-monaco-converter.ts +158 -158
  159. package/src/browser/style/index.css +267 -267
  160. package/src/browser/textmate/index.ts +20 -20
  161. package/src/browser/textmate/monaco-textmate-frontend-bindings.ts +94 -94
  162. package/src/browser/textmate/monaco-textmate-service.ts +187 -187
  163. package/src/browser/textmate/monaco-theme-registry.ts +176 -176
  164. package/src/browser/textmate/monaco-theme-types.ts +37 -37
  165. package/src/browser/textmate/textmate-contribution.ts +29 -29
  166. package/src/browser/textmate/textmate-registry.ts +129 -129
  167. package/src/browser/textmate/textmate-snippet-completion-provider.ts +73 -73
  168. package/src/browser/textmate/textmate-tokenizer.ts +84 -84
  169. package/src/browser/workspace-symbol-command.ts +196 -196
  170. package/src/package.spec.ts +28 -28
@@ -1,651 +1,651 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 SAP SE or an SAP affiliate company 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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import {
18
- ApplicationShell,
19
- InputBox, InputOptions, KeybindingRegistry, NormalizedQuickInputButton, PickOptions,
20
- QuickInputButton, QuickInputHideReason, QuickInputService, QuickPick, QuickPickItem,
21
- QuickPickItemButtonEvent, QuickPickItemHighlights, QuickPickOptions, QuickPickSeparator
22
- } from '@theia/core/lib/browser';
23
- import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
24
- import {
25
- IInputBox, IInputOptions, IKeyMods, IPickOptions, IQuickInput, IQuickInputButton,
26
- IQuickInputService, IQuickNavigateConfiguration, IQuickPick, IQuickPickItem, IQuickPickItemButtonEvent, IQuickPickSeparator, QuickPickInput
27
- } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/common/quickInput';
28
- import { IQuickInputOptions, IQuickInputStyles, QuickInputController } from '@theia/monaco-editor-core/esm/vs/base/parts/quickinput/browser/quickInput';
29
- import { MonacoResolvedKeybinding } from './monaco-resolved-keybinding';
30
- import { IQuickAccessController } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/common/quickAccess';
31
- import { QuickAccessController } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/browser/quickAccess';
32
- import { ContextKeyService as VSCodeContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
33
- import { IListOptions, List } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/list/listWidget';
34
- import * as monaco from '@theia/monaco-editor-core';
35
- import { ResolvedKeybinding } from '@theia/monaco-editor-core/esm/vs/base/common/keybindings';
36
- import { IInstantiationService } from '@theia/monaco-editor-core/esm/vs/platform/instantiation/common/instantiation';
37
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
38
- import { IMatch } from '@theia/monaco-editor-core/esm/vs/base/common/filters';
39
- import { IListRenderer, IListVirtualDelegate } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/list/list';
40
- import { Event } from '@theia/core';
41
- import { MonacoColorRegistry } from './monaco-color-registry';
42
- import { ThemeService } from '@theia/core/lib/browser/theming';
43
- import { IStandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/common/standaloneTheme';
44
-
45
- // Copied from @vscode/src/vs/base/parts/quickInput/browser/quickInputList.ts
46
- export interface IListElement {
47
- readonly index: number;
48
- readonly item: IQuickPickItem;
49
- readonly saneLabel: string;
50
- readonly saneAriaLabel: string;
51
- readonly saneDescription?: string;
52
- readonly saneDetail?: string;
53
- readonly labelHighlights?: IMatch[];
54
- readonly descriptionHighlights?: IMatch[];
55
- readonly detailHighlights?: IMatch[];
56
- readonly checked: boolean;
57
- readonly separator?: IQuickPickSeparator;
58
- readonly fireButtonTriggered: (event: IQuickPickItemButtonEvent<IQuickPickItem>) => void;
59
- }
60
-
61
- @injectable()
62
- export class MonacoQuickInputImplementation implements IQuickInputService {
63
- declare readonly _serviceBrand: undefined;
64
-
65
- controller: QuickInputController;
66
- quickAccess: IQuickAccessController;
67
-
68
- @inject(ApplicationShell)
69
- protected readonly shell: ApplicationShell;
70
-
71
- @inject(MonacoColorRegistry)
72
- protected readonly colorRegistry: MonacoColorRegistry;
73
-
74
- @inject(ThemeService)
75
- protected readonly themeService: ThemeService;
76
-
77
- @inject(VSCodeContextKeyService)
78
- protected readonly contextKeyService: VSCodeContextKeyService;
79
-
80
- protected container: HTMLElement;
81
- private quickInputList: List<unknown>;
82
-
83
- get backButton(): IQuickInputButton { return this.controller.backButton; }
84
- get onShow(): monaco.IEvent<void> { return this.controller.onShow; }
85
- get onHide(): monaco.IEvent<void> { return this.controller.onHide; }
86
-
87
- @postConstruct()
88
- protected init(): void {
89
- this.initContainer();
90
- this.initController();
91
- this.quickAccess = new QuickAccessController(this, StandaloneServices.get(IInstantiationService));
92
- this.controller.onShow(() => {
93
- this.container.style.top = this.shell.mainPanel.node.getBoundingClientRect().top + 'px';
94
- });
95
- this.themeService.initialized.then(() => this.controller.applyStyles(this.getStyles()));
96
- // Hook into the theming service of Monaco to ensure that the updates are ready.
97
- StandaloneServices.get(IStandaloneThemeService).onDidColorThemeChange(() => this.controller.applyStyles(this.getStyles()));
98
- window.addEventListener('resize', () => this.updateLayout());
99
- }
100
-
101
- setContextKey(key: string | undefined): void {
102
- if (key) {
103
- this.contextKeyService.createKey<string>(key, undefined);
104
- }
105
- }
106
-
107
- createQuickPick<T extends IQuickPickItem>(): IQuickPick<T> {
108
- return this.controller.createQuickPick<T>();
109
- }
110
-
111
- createInputBox(): IInputBox {
112
- return this.controller.createInputBox();
113
- }
114
-
115
- open(filter: string): void {
116
- this.quickAccess.show(filter);
117
- setTimeout(() => {
118
- this.quickInputList.focusNth(0);
119
- }, 300);
120
- }
121
-
122
- input(options?: IInputOptions, token?: monaco.CancellationToken): Promise<string | undefined> {
123
- return this.controller.input(options, token);
124
- }
125
-
126
- pick<T extends IQuickPickItem, O extends IPickOptions<T>>(
127
- picks: Promise<QuickPickInput<T>[]> | QuickPickInput<T>[], options?: O, token?: monaco.CancellationToken
128
- ): Promise<(O extends { canPickMany: true; } ? T[] : T) | undefined> {
129
- return this.controller.pick(picks, options, token);
130
- }
131
-
132
- hide(): void {
133
- this.controller.hide();
134
- }
135
-
136
- focus(): void {
137
- this.controller.focus();
138
- }
139
-
140
- toggle(): void {
141
- this.controller.toggle();
142
- }
143
-
144
- applyStyles(styles: IQuickInputStyles): void {
145
- this.controller.applyStyles(styles);
146
- }
147
-
148
- layout(dimension: monaco.editor.IDimension, titleBarOffset: number): void {
149
- this.controller.layout(dimension, titleBarOffset);
150
- }
151
-
152
- navigate(next: boolean, quickNavigate?: IQuickNavigateConfiguration): void {
153
- this.controller.navigate(next, quickNavigate);
154
- }
155
-
156
- dispose(): void {
157
- this.controller.dispose();
158
- }
159
-
160
- async cancel(): Promise<void> {
161
- this.controller.cancel();
162
- }
163
-
164
- async back(): Promise<void> {
165
- this.controller.back();
166
- }
167
-
168
- async accept(keyMods?: IKeyMods): Promise<void> {
169
- this.controller.accept(keyMods);
170
- }
171
-
172
- private initContainer(): void {
173
- const container = this.container = document.createElement('div');
174
- container.id = 'quick-input-container';
175
- document.body.appendChild(this.container);
176
- }
177
-
178
- private initController(): void {
179
- this.controller = new QuickInputController(this.getOptions());
180
- this.updateLayout();
181
- }
182
-
183
- private updateLayout(): void {
184
- // Initialize the layout using screen dimensions as monaco computes the actual sizing.
185
- // https://github.com/microsoft/vscode/blob/6261075646f055b99068d3688932416f2346dd3b/src/vs/base/parts/quickinput/browser/quickInput.ts#L1799
186
- this.controller.layout(this.getClientDimension(), 0);
187
- }
188
-
189
- private getClientDimension(): monaco.editor.IDimension {
190
- return { width: window.innerWidth, height: window.innerHeight };
191
- }
192
-
193
- private getOptions(): IQuickInputOptions {
194
- const options: IQuickInputOptions = {
195
- idPrefix: 'quickInput_',
196
- container: this.container,
197
- styles: { widget: {}, list: {}, inputBox: {}, countBadge: {}, button: {}, progressBar: {}, keybindingLabel: {}, },
198
- ignoreFocusOut: () => false,
199
- isScreenReaderOptimized: () => true,
200
- backKeybindingLabel: () => undefined,
201
- setContextKey: (id?: string) => this.setContextKey(id),
202
- returnFocus: () => this.container.focus(),
203
- createList: <T>(
204
- user: string, container: HTMLElement, delegate: IListVirtualDelegate<T>, renderers: IListRenderer<T, unknown>[], listOptions: IListOptions<T>
205
- ): List<T> => this.quickInputList = new List(user, container, delegate, renderers, listOptions),
206
- };
207
- return options;
208
- }
209
-
210
- // @monaco-uplift
211
- // Keep the styles up to date with https://github.com/microsoft/vscode/blob/7888ff3a6b104e9e2e3d0f7890ca92dd0828215f/src/vs/platform/quickinput/browser/quickInput.ts#L171.
212
- private getStyles(): IQuickInputStyles {
213
- return {
214
- widget: {
215
- quickInputBackground: this.colorRegistry.getColor('quickInput.background'),
216
- quickInputForeground: this.colorRegistry.getColor('quickInput.foreground'),
217
- quickInputTitleBackground: this.colorRegistry.getColor('quickInputTitle.background')
218
- },
219
- list: {
220
- listBackground: this.colorRegistry.getColor('quickInput.background'),
221
- listInactiveFocusForeground: this.colorRegistry.getColor('quickInputList.focusForeground'),
222
- listInactiveSelectionIconForeground: this.colorRegistry.getColor('quickInputList.focusIconForeground'),
223
- listInactiveFocusBackground: this.colorRegistry.getColor('quickInputList.focusBackground'),
224
- listFocusOutline: this.colorRegistry.getColor('activeContrastBorder'),
225
- listInactiveFocusOutline: this.colorRegistry.getColor('activeContrastBorder'),
226
- pickerGroupBorder: this.colorRegistry.getColor('pickerGroup.border'),
227
- pickerGroupForeground: this.colorRegistry.getColor('pickerGroup.foreground')
228
- },
229
- inputBox: {
230
- inputForeground: this.colorRegistry.getColor('inputForeground'),
231
- inputBackground: this.colorRegistry.getColor('inputBackground'),
232
- inputBorder: this.colorRegistry.getColor('inputBorder'),
233
- inputValidationInfoBackground: this.colorRegistry.getColor('inputValidation.infoBackground'),
234
- inputValidationInfoForeground: this.colorRegistry.getColor('inputValidation.infoForeground'),
235
- inputValidationInfoBorder: this.colorRegistry.getColor('inputValidation.infoBorder'),
236
- inputValidationWarningBackground: this.colorRegistry.getColor('inputValidation.warningBackground'),
237
- inputValidationWarningForeground: this.colorRegistry.getColor('inputValidation.warningForeground'),
238
- inputValidationWarningBorder: this.colorRegistry.getColor('inputValidation.warningBorder'),
239
- inputValidationErrorBackground: this.colorRegistry.getColor('inputValidation.errorBackground'),
240
- inputValidationErrorForeground: this.colorRegistry.getColor('inputValidation.errorForeground'),
241
- inputValidationErrorBorder: this.colorRegistry.getColor('inputValidation.errorBorder'),
242
- },
243
- countBadge: {
244
- badgeBackground: this.colorRegistry.getColor('badge.background'),
245
- badgeForeground: this.colorRegistry.getColor('badge.foreground'),
246
- badgeBorder: this.colorRegistry.getColor('contrastBorder')
247
- },
248
- button: {
249
- buttonForeground: this.colorRegistry.getColor('button.foreground'),
250
- buttonBackground: this.colorRegistry.getColor('button.background'),
251
- buttonHoverBackground: this.colorRegistry.getColor('button.hoverBackground'),
252
- buttonBorder: this.colorRegistry.getColor('contrastBorder')
253
- },
254
- progressBar: {
255
- progressBarBackground: this.colorRegistry.getColor('progressBar.background')
256
- },
257
- keybindingLabel: {
258
- keybindingLabelBackground: this.colorRegistry.getColor('keybindingLabe.background'),
259
- keybindingLabelForeground: this.colorRegistry.getColor('keybindingLabel.foreground'),
260
- keybindingLabelBorder: this.colorRegistry.getColor('keybindingLabel.border'),
261
- keybindingLabelBottomBorder: this.colorRegistry.getColor('keybindingLabel.bottomBorder'),
262
- keybindingLabelShadow: this.colorRegistry.getColor('widget.shadow')
263
- },
264
- };
265
- }
266
- }
267
-
268
- @injectable()
269
- export class MonacoQuickInputService implements QuickInputService {
270
- @inject(MonacoQuickInputImplementation)
271
- private monacoService: MonacoQuickInputImplementation;
272
-
273
- @inject(KeybindingRegistry)
274
- protected readonly keybindingRegistry: KeybindingRegistry;
275
-
276
- get backButton(): QuickInputButton {
277
- return this.monacoService.backButton;
278
- }
279
-
280
- get onShow(): Event<void> { return this.monacoService.onShow; }
281
- get onHide(): Event<void> { return this.monacoService.onHide; }
282
-
283
- open(filter: string): void {
284
- this.monacoService.open(filter);
285
- }
286
-
287
- createInputBox(): InputBox {
288
- return this.monacoService.createInputBox();
289
- }
290
-
291
- input(options?: InputOptions, token?: monaco.CancellationToken): Promise<string | undefined> {
292
- let inputOptions: IInputOptions | undefined;
293
- if (options) {
294
- const { validateInput, ...props } = options;
295
- inputOptions = { ...props };
296
- if (validateInput) {
297
- inputOptions.validateInput = async input => validateInput(input);
298
- }
299
- }
300
- return this.monacoService.input(inputOptions, token);
301
- }
302
-
303
- async pick<T extends QuickPickItem, O extends PickOptions<T> = PickOptions<T>>(
304
- picks: Promise<QuickPickInput<T>[]> | QuickPickInput<T>[], options?: O, token?: monaco.CancellationToken
305
- ): Promise<(O extends { canPickMany: true; } ? T[] : T) | undefined> {
306
- type M = T & { buttons?: NormalizedQuickInputButton[] };
307
- type R = (O extends { canPickMany: true; } ? T[] : T);
308
- const monacoPicks = (await picks).map(pick => {
309
- if (pick.type !== 'separator') {
310
- pick.buttons &&= pick.buttons.map(QuickInputButton.normalize);
311
- }
312
- return pick as M;
313
- });
314
- const monacoOptions = options as IPickOptions<M>;
315
- const picked = await this.monacoService.pick(monacoPicks, monacoOptions, token);
316
- if (!picked) { return picked; }
317
- if (options?.canPickMany) {
318
- return (Array.isArray(picked) ? picked : [picked]) as R;
319
- }
320
- return Array.isArray(picked) ? picked[0] : picked;
321
- }
322
-
323
- showQuickPick<T extends QuickPickItem>(items: Array<T | QuickPickSeparator>, options?: QuickPickOptions<T>): Promise<T | undefined> {
324
- return new Promise<T | undefined>((resolve, reject) => {
325
- const quickPick = this.monacoService.createQuickPick<MonacoQuickPickItem<T>>();
326
- const wrapped = this.wrapQuickPick(quickPick);
327
- wrapped.items = items;
328
-
329
- if (options) {
330
- wrapped.canSelectMany = !!options.canSelectMany;
331
- wrapped.contextKey = options.contextKey;
332
- wrapped.description = options.description;
333
- wrapped.enabled = options.enabled ?? true;
334
- wrapped.ignoreFocusOut = !!options.ignoreFocusOut;
335
- wrapped.matchOnDescription = options.matchOnDescription ?? true;
336
- wrapped.matchOnDetail = options.matchOnDetail ?? true;
337
- wrapped.keepScrollPosition = options.keepScrollPosition ?? false;
338
- wrapped.placeholder = options.placeholder;
339
- wrapped.step = options.step;
340
- wrapped.title = options.title;
341
- wrapped.totalSteps = options.totalSteps;
342
-
343
- if (options.activeItem) {
344
- wrapped.activeItems = [options.activeItem];
345
- }
346
-
347
- wrapped.onDidAccept(() => {
348
- if (options?.onDidAccept) {
349
- options.onDidAccept();
350
- }
351
- wrapped.hide();
352
- resolve(wrapped.selectedItems[0]);
353
- });
354
-
355
- wrapped.onDidHide(() => {
356
- if (options.onDidHide) {
357
- options.onDidHide();
358
- };
359
- wrapped.dispose();
360
- setTimeout(() => resolve(undefined));
361
- });
362
- wrapped.onDidChangeValue((filter: string) => {
363
- if (options.onDidChangeValue) {
364
- options.onDidChangeValue(wrapped, filter);
365
- }
366
- });
367
- wrapped.onDidChangeActive((activeItems: Array<T>) => {
368
- if (options.onDidChangeActive) {
369
- options.onDidChangeActive(wrapped, activeItems);
370
- }
371
- });
372
- wrapped.onDidTriggerButton((button: IQuickInputButton) => {
373
- if (options.onDidTriggerButton) {
374
- options.onDidTriggerButton(button);
375
- }
376
- });
377
- wrapped.onDidTriggerItemButton((event: QuickPickItemButtonEvent<T>) => {
378
- if (options.onDidTriggerItemButton) {
379
- // https://github.com/theia-ide/vscode/blob/standalone/0.23.x/src/vs/base/parts/quickinput/browser/quickInput.ts#L1387
380
- options.onDidTriggerItemButton(
381
- {
382
- ...event,
383
- removeItem: () => {
384
- wrapped.items = wrapped.items.filter(item => item !== event.item);
385
- wrapped.activeItems = wrapped.activeItems.filter(item => item !== event.item);
386
- }
387
- });
388
- }
389
- });
390
- wrapped.onDidChangeSelection((selectedItems: Array<T>) => {
391
- if (options.onDidChangeSelection) {
392
- options.onDidChangeSelection(wrapped, selectedItems);
393
- }
394
- });
395
- }
396
- wrapped.show();
397
- }).then(item => {
398
- if (item?.execute) {
399
- item.execute();
400
- }
401
- return item;
402
- });
403
- }
404
-
405
- createQuickPick<T extends QuickPickItem>(): QuickPick<T> {
406
- const quickPick = this.monacoService.createQuickPick<MonacoQuickPickItem<T>>();
407
- return this.wrapQuickPick(quickPick);
408
- }
409
-
410
- wrapQuickPick<T extends QuickPickItem>(wrapped: IQuickPick<MonacoQuickPickItem<T>>): QuickPick<T> {
411
- return new MonacoQuickPick(wrapped, this.keybindingRegistry);
412
- }
413
-
414
- protected convertItems<T extends QuickPickItem>(item: T): MonacoQuickPickItem<T> {
415
- return new MonacoQuickPickItem(item, this.keybindingRegistry);
416
- }
417
-
418
- hide(): void {
419
- return this.monacoService.hide();
420
- }
421
- }
422
-
423
- class MonacoQuickInput {
424
- constructor(protected readonly wrapped: IQuickInput) {
425
- }
426
-
427
- get onDidHide(): Event<{ reason: QuickInputHideReason }> { return this.wrapped.onDidHide; }
428
- get onDispose(): Event<void> { return this.wrapped.onDispose; }
429
-
430
- get title(): string | undefined {
431
- return this.wrapped.title;
432
- }
433
-
434
- set title(v: string | undefined) {
435
- this.wrapped.title = v;
436
- }
437
-
438
- get description(): string | undefined {
439
- return this.wrapped.description;
440
- }
441
-
442
- set description(v: string | undefined) {
443
- this.wrapped.description = v;
444
- }
445
- get step(): number | undefined {
446
- return this.wrapped.step;
447
- }
448
-
449
- set step(v: number | undefined) {
450
- this.wrapped.step = v;
451
- }
452
-
453
- get enabled(): boolean {
454
- return this.wrapped.enabled;
455
- }
456
-
457
- set enabled(v: boolean) {
458
- this.wrapped.enabled = v;
459
- }
460
- get totalSteps(): number | undefined {
461
- return this.wrapped.totalSteps;
462
- }
463
-
464
- set totalSteps(v: number | undefined) {
465
- this.wrapped.totalSteps = v;
466
- }
467
- get contextKey(): string | undefined {
468
- return this.wrapped.contextKey;
469
- }
470
-
471
- set contextKey(v: string | undefined) {
472
- this.wrapped.contextKey = v;
473
- }
474
-
475
- get busy(): boolean {
476
- return this.wrapped.busy;
477
- }
478
-
479
- set busy(v: boolean) {
480
- this.wrapped.busy = v;
481
- }
482
-
483
- get ignoreFocusOut(): boolean {
484
- return this.wrapped.ignoreFocusOut;
485
- }
486
-
487
- set ignoreFocusOut(v: boolean) {
488
- this.wrapped.ignoreFocusOut = v;
489
- }
490
-
491
- show(): void {
492
- this.wrapped.show();
493
- }
494
- hide(): void {
495
- this.wrapped.hide();
496
- }
497
- dispose(): void {
498
- this.wrapped.dispose();
499
- }
500
-
501
- }
502
-
503
- class MonacoQuickPick<T extends QuickPickItem> extends MonacoQuickInput implements QuickPick<T> {
504
- constructor(protected override readonly wrapped: IQuickPick<MonacoQuickPickItem<T>>, protected readonly keybindingRegistry: KeybindingRegistry) {
505
- super(wrapped);
506
- }
507
-
508
- get value(): string {
509
- return this.wrapped.value;
510
- };
511
-
512
- set value(v: string) {
513
- this.wrapped.value = v;
514
- }
515
-
516
- get placeholder(): string | undefined {
517
- return this.wrapped.placeholder;
518
- }
519
-
520
- set placeholder(v: string | undefined) {
521
- this.wrapped.placeholder = v;
522
- }
523
-
524
- get canSelectMany(): boolean {
525
- return this.wrapped.canSelectMany;
526
- }
527
-
528
- set canSelectMany(v: boolean) {
529
- this.wrapped.canSelectMany = v;
530
- }
531
-
532
- get matchOnDescription(): boolean {
533
- return this.wrapped.matchOnDescription;
534
- }
535
-
536
- set matchOnDescription(v: boolean) {
537
- this.wrapped.matchOnDescription = v;
538
- }
539
-
540
- get matchOnDetail(): boolean {
541
- return this.wrapped.matchOnDetail;
542
- }
543
-
544
- set matchOnDetail(v: boolean) {
545
- this.wrapped.matchOnDetail = v;
546
- }
547
-
548
- get keepScrollPosition(): boolean {
549
- return this.wrapped.keepScrollPosition;
550
- }
551
-
552
- set keepScrollPosition(v: boolean) {
553
- this.wrapped.keepScrollPosition = v;
554
- }
555
-
556
- get items(): readonly (T | QuickPickSeparator)[] {
557
- return this.wrapped.items.map(item => QuickPickSeparator.is(item) ? item : item.item);
558
- }
559
-
560
- set items(itms: readonly (T | QuickPickSeparator)[]) {
561
- // We need to store and apply the currently selected active items.
562
- // Since monaco compares these items by reference equality, creating new wrapped items will unmark any active items.
563
- // Assigning the `activeItems` again will restore all active items even after the items array has changed.
564
- // See also the `findMonacoItemReferences` method.
565
- const active = this.activeItems;
566
- this.wrapped.items = itms.map(item => QuickPickSeparator.is(item) ? item : new MonacoQuickPickItem<T>(item, this.keybindingRegistry));
567
- this.activeItems = active;
568
- }
569
-
570
- set activeItems(itms: readonly T[]) {
571
- this.wrapped.activeItems = this.findMonacoItemReferences(this.wrapped.items, itms);
572
- }
573
-
574
- get activeItems(): readonly (T)[] {
575
- return this.wrapped.activeItems.map(item => item.item);
576
- }
577
-
578
- set selectedItems(itms: readonly T[]) {
579
- this.wrapped.selectedItems = this.findMonacoItemReferences(this.wrapped.items, itms);
580
- }
581
-
582
- get selectedItems(): readonly (T)[] {
583
- return this.wrapped.selectedItems.map(item => item.item);
584
- }
585
-
586
- readonly onDidAccept: Event<{ inBackground: boolean }> = this.wrapped.onDidAccept;
587
- readonly onDidChangeValue: Event<string> = this.wrapped.onDidChangeValue;
588
- readonly onDidTriggerButton: Event<QuickInputButton> = this.wrapped.onDidTriggerButton;
589
- readonly onDidTriggerItemButton: Event<QuickPickItemButtonEvent<T>> =
590
- Event.map(this.wrapped.onDidTriggerItemButton, (evt: IQuickPickItemButtonEvent<MonacoQuickPickItem<T>>) => ({
591
- item: evt.item.item,
592
- button: evt.button
593
- }));
594
- readonly onDidChangeActive: Event<T[]> = Event.map(
595
- this.wrapped.onDidChangeActive,
596
- (items: MonacoQuickPickItem<T>[]) => items.map(item => item.item));
597
- readonly onDidChangeSelection: Event<T[]> = Event.map(
598
- this.wrapped.onDidChangeSelection, (items: MonacoQuickPickItem<T>[]) => items.map(item => item.item));
599
-
600
- /**
601
- * Monaco doesn't check for deep equality when setting the `activeItems` or `selectedItems`.
602
- * Instead we have to find the references of the monaco wrappers that contain the selected/active items
603
- */
604
- protected findMonacoItemReferences(source: readonly (MonacoQuickPickItem<T> | IQuickPickSeparator)[], items: readonly QuickPickItem[]): MonacoQuickPickItem<T>[] {
605
- const monacoReferences: MonacoQuickPickItem<T>[] = [];
606
- for (const item of items) {
607
- for (const wrappedItem of source) {
608
- if (!QuickPickSeparator.is(wrappedItem) && wrappedItem.item === item) {
609
- monacoReferences.push(wrappedItem);
610
- }
611
- }
612
- }
613
- return monacoReferences;
614
- }
615
- }
616
-
617
- export class MonacoQuickPickItem<T extends QuickPickItem> implements IQuickPickItem {
618
- readonly type?: 'item';
619
- readonly id?: string;
620
- readonly label: string;
621
- readonly meta?: string;
622
- readonly ariaLabel?: string;
623
- readonly description?: string;
624
- readonly detail?: string;
625
- readonly keybinding?: ResolvedKeybinding;
626
- readonly iconClasses?: string[];
627
- buttons?: IQuickInputButton[];
628
- readonly alwaysShow?: boolean;
629
- readonly highlights?: QuickPickItemHighlights;
630
-
631
- constructor(readonly item: T, kbRegistry: KeybindingRegistry) {
632
- this.type = item.type;
633
- this.id = item.id;
634
- this.label = item.label;
635
- this.meta = item.meta;
636
- this.ariaLabel = item.ariaLabel;
637
- this.description = item.description;
638
- this.detail = item.detail;
639
- this.keybinding = item.keySequence ? new MonacoResolvedKeybinding(item.keySequence, kbRegistry) : undefined;
640
- this.iconClasses = item.iconClasses;
641
- this.buttons = item.buttons?.map(QuickInputButton.normalize);
642
- this.alwaysShow = item.alwaysShow;
643
- this.highlights = item.highlights;
644
- }
645
-
646
- accept(): void {
647
- if (this.item.execute) {
648
- this.item.execute();
649
- }
650
- }
651
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 SAP SE or an SAP affiliate company 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import {
18
+ ApplicationShell,
19
+ InputBox, InputOptions, KeybindingRegistry, NormalizedQuickInputButton, PickOptions,
20
+ QuickInputButton, QuickInputHideReason, QuickInputService, QuickPick, QuickPickItem,
21
+ QuickPickItemButtonEvent, QuickPickItemHighlights, QuickPickOptions, QuickPickSeparator
22
+ } from '@theia/core/lib/browser';
23
+ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
24
+ import {
25
+ IInputBox, IInputOptions, IKeyMods, IPickOptions, IQuickInput, IQuickInputButton,
26
+ IQuickInputService, IQuickNavigateConfiguration, IQuickPick, IQuickPickItem, IQuickPickItemButtonEvent, IQuickPickSeparator, QuickPickInput
27
+ } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/common/quickInput';
28
+ import { IQuickInputOptions, IQuickInputStyles, QuickInputController } from '@theia/monaco-editor-core/esm/vs/base/parts/quickinput/browser/quickInput';
29
+ import { MonacoResolvedKeybinding } from './monaco-resolved-keybinding';
30
+ import { IQuickAccessController } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/common/quickAccess';
31
+ import { QuickAccessController } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/browser/quickAccess';
32
+ import { ContextKeyService as VSCodeContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
33
+ import { IListOptions, List } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/list/listWidget';
34
+ import * as monaco from '@theia/monaco-editor-core';
35
+ import { ResolvedKeybinding } from '@theia/monaco-editor-core/esm/vs/base/common/keybindings';
36
+ import { IInstantiationService } from '@theia/monaco-editor-core/esm/vs/platform/instantiation/common/instantiation';
37
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
38
+ import { IMatch } from '@theia/monaco-editor-core/esm/vs/base/common/filters';
39
+ import { IListRenderer, IListVirtualDelegate } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/list/list';
40
+ import { Event } from '@theia/core';
41
+ import { MonacoColorRegistry } from './monaco-color-registry';
42
+ import { ThemeService } from '@theia/core/lib/browser/theming';
43
+ import { IStandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/common/standaloneTheme';
44
+
45
+ // Copied from @vscode/src/vs/base/parts/quickInput/browser/quickInputList.ts
46
+ export interface IListElement {
47
+ readonly index: number;
48
+ readonly item: IQuickPickItem;
49
+ readonly saneLabel: string;
50
+ readonly saneAriaLabel: string;
51
+ readonly saneDescription?: string;
52
+ readonly saneDetail?: string;
53
+ readonly labelHighlights?: IMatch[];
54
+ readonly descriptionHighlights?: IMatch[];
55
+ readonly detailHighlights?: IMatch[];
56
+ readonly checked: boolean;
57
+ readonly separator?: IQuickPickSeparator;
58
+ readonly fireButtonTriggered: (event: IQuickPickItemButtonEvent<IQuickPickItem>) => void;
59
+ }
60
+
61
+ @injectable()
62
+ export class MonacoQuickInputImplementation implements IQuickInputService {
63
+ declare readonly _serviceBrand: undefined;
64
+
65
+ controller: QuickInputController;
66
+ quickAccess: IQuickAccessController;
67
+
68
+ @inject(ApplicationShell)
69
+ protected readonly shell: ApplicationShell;
70
+
71
+ @inject(MonacoColorRegistry)
72
+ protected readonly colorRegistry: MonacoColorRegistry;
73
+
74
+ @inject(ThemeService)
75
+ protected readonly themeService: ThemeService;
76
+
77
+ @inject(VSCodeContextKeyService)
78
+ protected readonly contextKeyService: VSCodeContextKeyService;
79
+
80
+ protected container: HTMLElement;
81
+ private quickInputList: List<unknown>;
82
+
83
+ get backButton(): IQuickInputButton { return this.controller.backButton; }
84
+ get onShow(): monaco.IEvent<void> { return this.controller.onShow; }
85
+ get onHide(): monaco.IEvent<void> { return this.controller.onHide; }
86
+
87
+ @postConstruct()
88
+ protected init(): void {
89
+ this.initContainer();
90
+ this.initController();
91
+ this.quickAccess = new QuickAccessController(this, StandaloneServices.get(IInstantiationService));
92
+ this.controller.onShow(() => {
93
+ this.container.style.top = this.shell.mainPanel.node.getBoundingClientRect().top + 'px';
94
+ });
95
+ this.themeService.initialized.then(() => this.controller.applyStyles(this.getStyles()));
96
+ // Hook into the theming service of Monaco to ensure that the updates are ready.
97
+ StandaloneServices.get(IStandaloneThemeService).onDidColorThemeChange(() => this.controller.applyStyles(this.getStyles()));
98
+ window.addEventListener('resize', () => this.updateLayout());
99
+ }
100
+
101
+ setContextKey(key: string | undefined): void {
102
+ if (key) {
103
+ this.contextKeyService.createKey<string>(key, undefined);
104
+ }
105
+ }
106
+
107
+ createQuickPick<T extends IQuickPickItem>(): IQuickPick<T> {
108
+ return this.controller.createQuickPick<T>();
109
+ }
110
+
111
+ createInputBox(): IInputBox {
112
+ return this.controller.createInputBox();
113
+ }
114
+
115
+ open(filter: string): void {
116
+ this.quickAccess.show(filter);
117
+ setTimeout(() => {
118
+ this.quickInputList.focusNth(0);
119
+ }, 300);
120
+ }
121
+
122
+ input(options?: IInputOptions, token?: monaco.CancellationToken): Promise<string | undefined> {
123
+ return this.controller.input(options, token);
124
+ }
125
+
126
+ pick<T extends IQuickPickItem, O extends IPickOptions<T>>(
127
+ picks: Promise<QuickPickInput<T>[]> | QuickPickInput<T>[], options?: O, token?: monaco.CancellationToken
128
+ ): Promise<(O extends { canPickMany: true; } ? T[] : T) | undefined> {
129
+ return this.controller.pick(picks, options, token);
130
+ }
131
+
132
+ hide(): void {
133
+ this.controller.hide();
134
+ }
135
+
136
+ focus(): void {
137
+ this.controller.focus();
138
+ }
139
+
140
+ toggle(): void {
141
+ this.controller.toggle();
142
+ }
143
+
144
+ applyStyles(styles: IQuickInputStyles): void {
145
+ this.controller.applyStyles(styles);
146
+ }
147
+
148
+ layout(dimension: monaco.editor.IDimension, titleBarOffset: number): void {
149
+ this.controller.layout(dimension, titleBarOffset);
150
+ }
151
+
152
+ navigate(next: boolean, quickNavigate?: IQuickNavigateConfiguration): void {
153
+ this.controller.navigate(next, quickNavigate);
154
+ }
155
+
156
+ dispose(): void {
157
+ this.controller.dispose();
158
+ }
159
+
160
+ async cancel(): Promise<void> {
161
+ this.controller.cancel();
162
+ }
163
+
164
+ async back(): Promise<void> {
165
+ this.controller.back();
166
+ }
167
+
168
+ async accept(keyMods?: IKeyMods): Promise<void> {
169
+ this.controller.accept(keyMods);
170
+ }
171
+
172
+ private initContainer(): void {
173
+ const container = this.container = document.createElement('div');
174
+ container.id = 'quick-input-container';
175
+ document.body.appendChild(this.container);
176
+ }
177
+
178
+ private initController(): void {
179
+ this.controller = new QuickInputController(this.getOptions());
180
+ this.updateLayout();
181
+ }
182
+
183
+ private updateLayout(): void {
184
+ // Initialize the layout using screen dimensions as monaco computes the actual sizing.
185
+ // https://github.com/microsoft/vscode/blob/6261075646f055b99068d3688932416f2346dd3b/src/vs/base/parts/quickinput/browser/quickInput.ts#L1799
186
+ this.controller.layout(this.getClientDimension(), 0);
187
+ }
188
+
189
+ private getClientDimension(): monaco.editor.IDimension {
190
+ return { width: window.innerWidth, height: window.innerHeight };
191
+ }
192
+
193
+ private getOptions(): IQuickInputOptions {
194
+ const options: IQuickInputOptions = {
195
+ idPrefix: 'quickInput_',
196
+ container: this.container,
197
+ styles: { widget: {}, list: {}, inputBox: {}, countBadge: {}, button: {}, progressBar: {}, keybindingLabel: {}, },
198
+ ignoreFocusOut: () => false,
199
+ isScreenReaderOptimized: () => true,
200
+ backKeybindingLabel: () => undefined,
201
+ setContextKey: (id?: string) => this.setContextKey(id),
202
+ returnFocus: () => this.container.focus(),
203
+ createList: <T>(
204
+ user: string, container: HTMLElement, delegate: IListVirtualDelegate<T>, renderers: IListRenderer<T, unknown>[], listOptions: IListOptions<T>
205
+ ): List<T> => this.quickInputList = new List(user, container, delegate, renderers, listOptions),
206
+ };
207
+ return options;
208
+ }
209
+
210
+ // @monaco-uplift
211
+ // Keep the styles up to date with https://github.com/microsoft/vscode/blob/7888ff3a6b104e9e2e3d0f7890ca92dd0828215f/src/vs/platform/quickinput/browser/quickInput.ts#L171.
212
+ private getStyles(): IQuickInputStyles {
213
+ return {
214
+ widget: {
215
+ quickInputBackground: this.colorRegistry.getColor('quickInput.background'),
216
+ quickInputForeground: this.colorRegistry.getColor('quickInput.foreground'),
217
+ quickInputTitleBackground: this.colorRegistry.getColor('quickInputTitle.background')
218
+ },
219
+ list: {
220
+ listBackground: this.colorRegistry.getColor('quickInput.background'),
221
+ listInactiveFocusForeground: this.colorRegistry.getColor('quickInputList.focusForeground'),
222
+ listInactiveSelectionIconForeground: this.colorRegistry.getColor('quickInputList.focusIconForeground'),
223
+ listInactiveFocusBackground: this.colorRegistry.getColor('quickInputList.focusBackground'),
224
+ listFocusOutline: this.colorRegistry.getColor('activeContrastBorder'),
225
+ listInactiveFocusOutline: this.colorRegistry.getColor('activeContrastBorder'),
226
+ pickerGroupBorder: this.colorRegistry.getColor('pickerGroup.border'),
227
+ pickerGroupForeground: this.colorRegistry.getColor('pickerGroup.foreground')
228
+ },
229
+ inputBox: {
230
+ inputForeground: this.colorRegistry.getColor('inputForeground'),
231
+ inputBackground: this.colorRegistry.getColor('inputBackground'),
232
+ inputBorder: this.colorRegistry.getColor('inputBorder'),
233
+ inputValidationInfoBackground: this.colorRegistry.getColor('inputValidation.infoBackground'),
234
+ inputValidationInfoForeground: this.colorRegistry.getColor('inputValidation.infoForeground'),
235
+ inputValidationInfoBorder: this.colorRegistry.getColor('inputValidation.infoBorder'),
236
+ inputValidationWarningBackground: this.colorRegistry.getColor('inputValidation.warningBackground'),
237
+ inputValidationWarningForeground: this.colorRegistry.getColor('inputValidation.warningForeground'),
238
+ inputValidationWarningBorder: this.colorRegistry.getColor('inputValidation.warningBorder'),
239
+ inputValidationErrorBackground: this.colorRegistry.getColor('inputValidation.errorBackground'),
240
+ inputValidationErrorForeground: this.colorRegistry.getColor('inputValidation.errorForeground'),
241
+ inputValidationErrorBorder: this.colorRegistry.getColor('inputValidation.errorBorder'),
242
+ },
243
+ countBadge: {
244
+ badgeBackground: this.colorRegistry.getColor('badge.background'),
245
+ badgeForeground: this.colorRegistry.getColor('badge.foreground'),
246
+ badgeBorder: this.colorRegistry.getColor('contrastBorder')
247
+ },
248
+ button: {
249
+ buttonForeground: this.colorRegistry.getColor('button.foreground'),
250
+ buttonBackground: this.colorRegistry.getColor('button.background'),
251
+ buttonHoverBackground: this.colorRegistry.getColor('button.hoverBackground'),
252
+ buttonBorder: this.colorRegistry.getColor('contrastBorder')
253
+ },
254
+ progressBar: {
255
+ progressBarBackground: this.colorRegistry.getColor('progressBar.background')
256
+ },
257
+ keybindingLabel: {
258
+ keybindingLabelBackground: this.colorRegistry.getColor('keybindingLabe.background'),
259
+ keybindingLabelForeground: this.colorRegistry.getColor('keybindingLabel.foreground'),
260
+ keybindingLabelBorder: this.colorRegistry.getColor('keybindingLabel.border'),
261
+ keybindingLabelBottomBorder: this.colorRegistry.getColor('keybindingLabel.bottomBorder'),
262
+ keybindingLabelShadow: this.colorRegistry.getColor('widget.shadow')
263
+ },
264
+ };
265
+ }
266
+ }
267
+
268
+ @injectable()
269
+ export class MonacoQuickInputService implements QuickInputService {
270
+ @inject(MonacoQuickInputImplementation)
271
+ private monacoService: MonacoQuickInputImplementation;
272
+
273
+ @inject(KeybindingRegistry)
274
+ protected readonly keybindingRegistry: KeybindingRegistry;
275
+
276
+ get backButton(): QuickInputButton {
277
+ return this.monacoService.backButton;
278
+ }
279
+
280
+ get onShow(): Event<void> { return this.monacoService.onShow; }
281
+ get onHide(): Event<void> { return this.monacoService.onHide; }
282
+
283
+ open(filter: string): void {
284
+ this.monacoService.open(filter);
285
+ }
286
+
287
+ createInputBox(): InputBox {
288
+ return this.monacoService.createInputBox();
289
+ }
290
+
291
+ input(options?: InputOptions, token?: monaco.CancellationToken): Promise<string | undefined> {
292
+ let inputOptions: IInputOptions | undefined;
293
+ if (options) {
294
+ const { validateInput, ...props } = options;
295
+ inputOptions = { ...props };
296
+ if (validateInput) {
297
+ inputOptions.validateInput = async input => validateInput(input);
298
+ }
299
+ }
300
+ return this.monacoService.input(inputOptions, token);
301
+ }
302
+
303
+ async pick<T extends QuickPickItem, O extends PickOptions<T> = PickOptions<T>>(
304
+ picks: Promise<QuickPickInput<T>[]> | QuickPickInput<T>[], options?: O, token?: monaco.CancellationToken
305
+ ): Promise<(O extends { canPickMany: true; } ? T[] : T) | undefined> {
306
+ type M = T & { buttons?: NormalizedQuickInputButton[] };
307
+ type R = (O extends { canPickMany: true; } ? T[] : T);
308
+ const monacoPicks = (await picks).map(pick => {
309
+ if (pick.type !== 'separator') {
310
+ pick.buttons &&= pick.buttons.map(QuickInputButton.normalize);
311
+ }
312
+ return pick as M;
313
+ });
314
+ const monacoOptions = options as IPickOptions<M>;
315
+ const picked = await this.monacoService.pick(monacoPicks, monacoOptions, token);
316
+ if (!picked) { return picked; }
317
+ if (options?.canPickMany) {
318
+ return (Array.isArray(picked) ? picked : [picked]) as R;
319
+ }
320
+ return Array.isArray(picked) ? picked[0] : picked;
321
+ }
322
+
323
+ showQuickPick<T extends QuickPickItem>(items: Array<T | QuickPickSeparator>, options?: QuickPickOptions<T>): Promise<T | undefined> {
324
+ return new Promise<T | undefined>((resolve, reject) => {
325
+ const quickPick = this.monacoService.createQuickPick<MonacoQuickPickItem<T>>();
326
+ const wrapped = this.wrapQuickPick(quickPick);
327
+ wrapped.items = items;
328
+
329
+ if (options) {
330
+ wrapped.canSelectMany = !!options.canSelectMany;
331
+ wrapped.contextKey = options.contextKey;
332
+ wrapped.description = options.description;
333
+ wrapped.enabled = options.enabled ?? true;
334
+ wrapped.ignoreFocusOut = !!options.ignoreFocusOut;
335
+ wrapped.matchOnDescription = options.matchOnDescription ?? true;
336
+ wrapped.matchOnDetail = options.matchOnDetail ?? true;
337
+ wrapped.keepScrollPosition = options.keepScrollPosition ?? false;
338
+ wrapped.placeholder = options.placeholder;
339
+ wrapped.step = options.step;
340
+ wrapped.title = options.title;
341
+ wrapped.totalSteps = options.totalSteps;
342
+
343
+ if (options.activeItem) {
344
+ wrapped.activeItems = [options.activeItem];
345
+ }
346
+
347
+ wrapped.onDidAccept(() => {
348
+ if (options?.onDidAccept) {
349
+ options.onDidAccept();
350
+ }
351
+ wrapped.hide();
352
+ resolve(wrapped.selectedItems[0]);
353
+ });
354
+
355
+ wrapped.onDidHide(() => {
356
+ if (options.onDidHide) {
357
+ options.onDidHide();
358
+ };
359
+ wrapped.dispose();
360
+ setTimeout(() => resolve(undefined));
361
+ });
362
+ wrapped.onDidChangeValue((filter: string) => {
363
+ if (options.onDidChangeValue) {
364
+ options.onDidChangeValue(wrapped, filter);
365
+ }
366
+ });
367
+ wrapped.onDidChangeActive((activeItems: Array<T>) => {
368
+ if (options.onDidChangeActive) {
369
+ options.onDidChangeActive(wrapped, activeItems);
370
+ }
371
+ });
372
+ wrapped.onDidTriggerButton((button: IQuickInputButton) => {
373
+ if (options.onDidTriggerButton) {
374
+ options.onDidTriggerButton(button);
375
+ }
376
+ });
377
+ wrapped.onDidTriggerItemButton((event: QuickPickItemButtonEvent<T>) => {
378
+ if (options.onDidTriggerItemButton) {
379
+ // https://github.com/theia-ide/vscode/blob/standalone/0.23.x/src/vs/base/parts/quickinput/browser/quickInput.ts#L1387
380
+ options.onDidTriggerItemButton(
381
+ {
382
+ ...event,
383
+ removeItem: () => {
384
+ wrapped.items = wrapped.items.filter(item => item !== event.item);
385
+ wrapped.activeItems = wrapped.activeItems.filter(item => item !== event.item);
386
+ }
387
+ });
388
+ }
389
+ });
390
+ wrapped.onDidChangeSelection((selectedItems: Array<T>) => {
391
+ if (options.onDidChangeSelection) {
392
+ options.onDidChangeSelection(wrapped, selectedItems);
393
+ }
394
+ });
395
+ }
396
+ wrapped.show();
397
+ }).then(item => {
398
+ if (item?.execute) {
399
+ item.execute();
400
+ }
401
+ return item;
402
+ });
403
+ }
404
+
405
+ createQuickPick<T extends QuickPickItem>(): QuickPick<T> {
406
+ const quickPick = this.monacoService.createQuickPick<MonacoQuickPickItem<T>>();
407
+ return this.wrapQuickPick(quickPick);
408
+ }
409
+
410
+ wrapQuickPick<T extends QuickPickItem>(wrapped: IQuickPick<MonacoQuickPickItem<T>>): QuickPick<T> {
411
+ return new MonacoQuickPick(wrapped, this.keybindingRegistry);
412
+ }
413
+
414
+ protected convertItems<T extends QuickPickItem>(item: T): MonacoQuickPickItem<T> {
415
+ return new MonacoQuickPickItem(item, this.keybindingRegistry);
416
+ }
417
+
418
+ hide(): void {
419
+ return this.monacoService.hide();
420
+ }
421
+ }
422
+
423
+ class MonacoQuickInput {
424
+ constructor(protected readonly wrapped: IQuickInput) {
425
+ }
426
+
427
+ get onDidHide(): Event<{ reason: QuickInputHideReason }> { return this.wrapped.onDidHide; }
428
+ get onDispose(): Event<void> { return this.wrapped.onDispose; }
429
+
430
+ get title(): string | undefined {
431
+ return this.wrapped.title;
432
+ }
433
+
434
+ set title(v: string | undefined) {
435
+ this.wrapped.title = v;
436
+ }
437
+
438
+ get description(): string | undefined {
439
+ return this.wrapped.description;
440
+ }
441
+
442
+ set description(v: string | undefined) {
443
+ this.wrapped.description = v;
444
+ }
445
+ get step(): number | undefined {
446
+ return this.wrapped.step;
447
+ }
448
+
449
+ set step(v: number | undefined) {
450
+ this.wrapped.step = v;
451
+ }
452
+
453
+ get enabled(): boolean {
454
+ return this.wrapped.enabled;
455
+ }
456
+
457
+ set enabled(v: boolean) {
458
+ this.wrapped.enabled = v;
459
+ }
460
+ get totalSteps(): number | undefined {
461
+ return this.wrapped.totalSteps;
462
+ }
463
+
464
+ set totalSteps(v: number | undefined) {
465
+ this.wrapped.totalSteps = v;
466
+ }
467
+ get contextKey(): string | undefined {
468
+ return this.wrapped.contextKey;
469
+ }
470
+
471
+ set contextKey(v: string | undefined) {
472
+ this.wrapped.contextKey = v;
473
+ }
474
+
475
+ get busy(): boolean {
476
+ return this.wrapped.busy;
477
+ }
478
+
479
+ set busy(v: boolean) {
480
+ this.wrapped.busy = v;
481
+ }
482
+
483
+ get ignoreFocusOut(): boolean {
484
+ return this.wrapped.ignoreFocusOut;
485
+ }
486
+
487
+ set ignoreFocusOut(v: boolean) {
488
+ this.wrapped.ignoreFocusOut = v;
489
+ }
490
+
491
+ show(): void {
492
+ this.wrapped.show();
493
+ }
494
+ hide(): void {
495
+ this.wrapped.hide();
496
+ }
497
+ dispose(): void {
498
+ this.wrapped.dispose();
499
+ }
500
+
501
+ }
502
+
503
+ class MonacoQuickPick<T extends QuickPickItem> extends MonacoQuickInput implements QuickPick<T> {
504
+ constructor(protected override readonly wrapped: IQuickPick<MonacoQuickPickItem<T>>, protected readonly keybindingRegistry: KeybindingRegistry) {
505
+ super(wrapped);
506
+ }
507
+
508
+ get value(): string {
509
+ return this.wrapped.value;
510
+ };
511
+
512
+ set value(v: string) {
513
+ this.wrapped.value = v;
514
+ }
515
+
516
+ get placeholder(): string | undefined {
517
+ return this.wrapped.placeholder;
518
+ }
519
+
520
+ set placeholder(v: string | undefined) {
521
+ this.wrapped.placeholder = v;
522
+ }
523
+
524
+ get canSelectMany(): boolean {
525
+ return this.wrapped.canSelectMany;
526
+ }
527
+
528
+ set canSelectMany(v: boolean) {
529
+ this.wrapped.canSelectMany = v;
530
+ }
531
+
532
+ get matchOnDescription(): boolean {
533
+ return this.wrapped.matchOnDescription;
534
+ }
535
+
536
+ set matchOnDescription(v: boolean) {
537
+ this.wrapped.matchOnDescription = v;
538
+ }
539
+
540
+ get matchOnDetail(): boolean {
541
+ return this.wrapped.matchOnDetail;
542
+ }
543
+
544
+ set matchOnDetail(v: boolean) {
545
+ this.wrapped.matchOnDetail = v;
546
+ }
547
+
548
+ get keepScrollPosition(): boolean {
549
+ return this.wrapped.keepScrollPosition;
550
+ }
551
+
552
+ set keepScrollPosition(v: boolean) {
553
+ this.wrapped.keepScrollPosition = v;
554
+ }
555
+
556
+ get items(): readonly (T | QuickPickSeparator)[] {
557
+ return this.wrapped.items.map(item => QuickPickSeparator.is(item) ? item : item.item);
558
+ }
559
+
560
+ set items(itms: readonly (T | QuickPickSeparator)[]) {
561
+ // We need to store and apply the currently selected active items.
562
+ // Since monaco compares these items by reference equality, creating new wrapped items will unmark any active items.
563
+ // Assigning the `activeItems` again will restore all active items even after the items array has changed.
564
+ // See also the `findMonacoItemReferences` method.
565
+ const active = this.activeItems;
566
+ this.wrapped.items = itms.map(item => QuickPickSeparator.is(item) ? item : new MonacoQuickPickItem<T>(item, this.keybindingRegistry));
567
+ this.activeItems = active;
568
+ }
569
+
570
+ set activeItems(itms: readonly T[]) {
571
+ this.wrapped.activeItems = this.findMonacoItemReferences(this.wrapped.items, itms);
572
+ }
573
+
574
+ get activeItems(): readonly (T)[] {
575
+ return this.wrapped.activeItems.map(item => item.item);
576
+ }
577
+
578
+ set selectedItems(itms: readonly T[]) {
579
+ this.wrapped.selectedItems = this.findMonacoItemReferences(this.wrapped.items, itms);
580
+ }
581
+
582
+ get selectedItems(): readonly (T)[] {
583
+ return this.wrapped.selectedItems.map(item => item.item);
584
+ }
585
+
586
+ readonly onDidAccept: Event<{ inBackground: boolean }> = this.wrapped.onDidAccept;
587
+ readonly onDidChangeValue: Event<string> = this.wrapped.onDidChangeValue;
588
+ readonly onDidTriggerButton: Event<QuickInputButton> = this.wrapped.onDidTriggerButton;
589
+ readonly onDidTriggerItemButton: Event<QuickPickItemButtonEvent<T>> =
590
+ Event.map(this.wrapped.onDidTriggerItemButton, (evt: IQuickPickItemButtonEvent<MonacoQuickPickItem<T>>) => ({
591
+ item: evt.item.item,
592
+ button: evt.button
593
+ }));
594
+ readonly onDidChangeActive: Event<T[]> = Event.map(
595
+ this.wrapped.onDidChangeActive,
596
+ (items: MonacoQuickPickItem<T>[]) => items.map(item => item.item));
597
+ readonly onDidChangeSelection: Event<T[]> = Event.map(
598
+ this.wrapped.onDidChangeSelection, (items: MonacoQuickPickItem<T>[]) => items.map(item => item.item));
599
+
600
+ /**
601
+ * Monaco doesn't check for deep equality when setting the `activeItems` or `selectedItems`.
602
+ * Instead we have to find the references of the monaco wrappers that contain the selected/active items
603
+ */
604
+ protected findMonacoItemReferences(source: readonly (MonacoQuickPickItem<T> | IQuickPickSeparator)[], items: readonly QuickPickItem[]): MonacoQuickPickItem<T>[] {
605
+ const monacoReferences: MonacoQuickPickItem<T>[] = [];
606
+ for (const item of items) {
607
+ for (const wrappedItem of source) {
608
+ if (!QuickPickSeparator.is(wrappedItem) && wrappedItem.item === item) {
609
+ monacoReferences.push(wrappedItem);
610
+ }
611
+ }
612
+ }
613
+ return monacoReferences;
614
+ }
615
+ }
616
+
617
+ export class MonacoQuickPickItem<T extends QuickPickItem> implements IQuickPickItem {
618
+ readonly type?: 'item';
619
+ readonly id?: string;
620
+ readonly label: string;
621
+ readonly meta?: string;
622
+ readonly ariaLabel?: string;
623
+ readonly description?: string;
624
+ readonly detail?: string;
625
+ readonly keybinding?: ResolvedKeybinding;
626
+ readonly iconClasses?: string[];
627
+ buttons?: IQuickInputButton[];
628
+ readonly alwaysShow?: boolean;
629
+ readonly highlights?: QuickPickItemHighlights;
630
+
631
+ constructor(readonly item: T, kbRegistry: KeybindingRegistry) {
632
+ this.type = item.type;
633
+ this.id = item.id;
634
+ this.label = item.label;
635
+ this.meta = item.meta;
636
+ this.ariaLabel = item.ariaLabel;
637
+ this.description = item.description;
638
+ this.detail = item.detail;
639
+ this.keybinding = item.keySequence ? new MonacoResolvedKeybinding(item.keySequence, kbRegistry) : undefined;
640
+ this.iconClasses = item.iconClasses;
641
+ this.buttons = item.buttons?.map(QuickInputButton.normalize);
642
+ this.alwaysShow = item.alwaysShow;
643
+ this.highlights = item.highlights;
644
+ }
645
+
646
+ accept(): void {
647
+ if (this.item.execute) {
648
+ this.item.execute();
649
+ }
650
+ }
651
+ }