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

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