@theia/monaco 1.34.2 → 1.34.3

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,498 +1,498 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2018 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- var __param = (this && this.__param) || function (paramIndex, decorator) {
27
- return function (target, key) { decorator(target, key, paramIndex); }
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.MonacoEditor = exports.MonacoEditorServices = void 0;
31
- const inversify_1 = require("@theia/core/shared/inversify");
32
- const domutils_1 = require("@theia/core/shared/@phosphor/domutils");
33
- const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
34
- const common_1 = require("@theia/core/lib/common");
35
- const monaco_to_protocol_converter_1 = require("./monaco-to-protocol-converter");
36
- const protocol_to_monaco_converter_1 = require("./protocol-to-monaco-converter");
37
- const encodings_1 = require("@theia/core/lib/common/encodings");
38
- const monaco = require("@theia/monaco-editor-core");
39
- const standaloneServices_1 = require("@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices");
40
- const language_1 = require("@theia/monaco-editor-core/esm/vs/editor/common/languages/language");
41
- const serviceCollection_1 = require("@theia/monaco-editor-core/esm/vs/platform/instantiation/common/serviceCollection");
42
- const standaloneCodeEditor_1 = require("@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor");
43
- let MonacoEditorServices = class MonacoEditorServices {
44
- constructor(services) {
45
- Object.assign(this, services);
46
- }
47
- };
48
- __decorate([
49
- (0, inversify_1.inject)(monaco_to_protocol_converter_1.MonacoToProtocolConverter),
50
- __metadata("design:type", monaco_to_protocol_converter_1.MonacoToProtocolConverter)
51
- ], MonacoEditorServices.prototype, "m2p", void 0);
52
- __decorate([
53
- (0, inversify_1.inject)(protocol_to_monaco_converter_1.ProtocolToMonacoConverter),
54
- __metadata("design:type", protocol_to_monaco_converter_1.ProtocolToMonacoConverter)
55
- ], MonacoEditorServices.prototype, "p2m", void 0);
56
- __decorate([
57
- (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
58
- __metadata("design:type", Object)
59
- ], MonacoEditorServices.prototype, "contextKeyService", void 0);
60
- MonacoEditorServices = __decorate([
61
- (0, inversify_1.injectable)(),
62
- __param(0, (0, inversify_1.unmanaged)()),
63
- __metadata("design:paramtypes", [MonacoEditorServices])
64
- ], MonacoEditorServices);
65
- exports.MonacoEditorServices = MonacoEditorServices;
66
- class MonacoEditor extends MonacoEditorServices {
67
- constructor(uri, document, node, services, options, override) {
68
- super(services);
69
- this.uri = uri;
70
- this.document = document;
71
- this.node = node;
72
- this.toDispose = new common_1.DisposableCollection();
73
- this.onCursorPositionChangedEmitter = new common_1.Emitter();
74
- this.onSelectionChangedEmitter = new common_1.Emitter();
75
- this.onFocusChangedEmitter = new common_1.Emitter();
76
- this.onDocumentContentChangedEmitter = new common_1.Emitter();
77
- this.onMouseDownEmitter = new common_1.Emitter();
78
- this.onLanguageChangedEmitter = new common_1.Emitter();
79
- this.onLanguageChanged = this.onLanguageChangedEmitter.event;
80
- this.onScrollChangedEmitter = new common_1.Emitter();
81
- this.onEncodingChanged = this.document.onDidChangeEncoding;
82
- this.onResizeEmitter = new common_1.Emitter();
83
- this.onDidResize = this.onResizeEmitter.event;
84
- this.documents = new Set();
85
- /* `true` because it is derived from an URI during the instantiation */
86
- this._languageAutoDetected = true;
87
- this.toDispose.pushAll([
88
- this.onCursorPositionChangedEmitter,
89
- this.onSelectionChangedEmitter,
90
- this.onFocusChangedEmitter,
91
- this.onDocumentContentChangedEmitter,
92
- this.onMouseDownEmitter,
93
- this.onLanguageChangedEmitter,
94
- this.onScrollChangedEmitter
95
- ]);
96
- this.documents.add(document);
97
- this.autoSizing = options && options.autoSizing !== undefined ? options.autoSizing : false;
98
- this.minHeight = options && options.minHeight !== undefined ? options.minHeight : -1;
99
- this.maxHeight = options && options.maxHeight !== undefined ? options.maxHeight : -1;
100
- this.toDispose.push(this.create(options, override));
101
- this.addHandlers(this.editor);
102
- }
103
- getEncoding() {
104
- return this.document.getEncoding() || encodings_1.UTF8;
105
- }
106
- setEncoding(encoding, mode) {
107
- return this.document.setEncoding(encoding, mode);
108
- }
109
- create(options, override) {
110
- const combinedOptions = Object.assign(Object.assign({}, options), { lightbulb: { enabled: true }, fixedOverflowWidgets: true, scrollbar: Object.assign({ useShadows: false, verticalHasArrows: false, horizontalHasArrows: false, verticalScrollbarSize: 10, horizontalScrollbarSize: 10 }, options === null || options === void 0 ? void 0 : options.scrollbar) });
111
- const instantiator = this.getInstantiatorWithOverrides(override);
112
- /**
113
- * @monaco-uplift. Should be guaranteed to work.
114
- * Incomparable enums prevent TypeScript from believing that public IStandaloneCodeEditor is satisfied by private StandaloneCodeEditor
115
- */
116
- return this.editor = instantiator.createInstance(standaloneCodeEditor_1.StandaloneEditor, this.node, combinedOptions);
117
- }
118
- getInstantiatorWithOverrides(override) {
119
- const instantiator = standaloneServices_1.StandaloneServices.initialize({});
120
- if (override) {
121
- const overrideServices = new serviceCollection_1.ServiceCollection(...override);
122
- return instantiator.createChild(overrideServices);
123
- }
124
- return instantiator;
125
- }
126
- addHandlers(codeEditor) {
127
- this.toDispose.push(codeEditor.onDidChangeModelLanguage(e => this.fireLanguageChanged(e.newLanguage)));
128
- this.toDispose.push(codeEditor.onDidChangeConfiguration(() => this.refresh()));
129
- this.toDispose.push(codeEditor.onDidChangeModel(() => this.refresh()));
130
- this.toDispose.push(codeEditor.onDidChangeModelContent(e => {
131
- this.refresh();
132
- this.onDocumentContentChangedEmitter.fire({ document: this.document, contentChanges: e.changes.map(this.mapModelContentChange.bind(this)) });
133
- }));
134
- this.toDispose.push(codeEditor.onDidChangeCursorPosition(() => this.onCursorPositionChangedEmitter.fire(this.cursor)));
135
- this.toDispose.push(codeEditor.onDidChangeCursorSelection(() => this.onSelectionChangedEmitter.fire(this.selection)));
136
- this.toDispose.push(codeEditor.onDidFocusEditorText(() => this.onFocusChangedEmitter.fire(this.isFocused())));
137
- this.toDispose.push(codeEditor.onDidBlurEditorText(() => this.onFocusChangedEmitter.fire(this.isFocused())));
138
- this.toDispose.push(codeEditor.onMouseDown(e => {
139
- const { element, position, range } = e.target;
140
- this.onMouseDownEmitter.fire({
141
- target: Object.assign(Object.assign({}, e.target), { element: element || undefined, mouseColumn: this.m2p.asPosition(undefined, e.target.mouseColumn).character, range: range && this.m2p.asRange(range) || undefined, position: position && this.m2p.asPosition(position.lineNumber, position.column) || undefined, detail: e.target.detail || {} }),
142
- event: e.event.browserEvent
143
- });
144
- }));
145
- this.toDispose.push(codeEditor.onDidScrollChange(e => {
146
- this.onScrollChangedEmitter.fire(undefined);
147
- }));
148
- }
149
- getVisibleRanges() {
150
- return this.editor.getVisibleRanges().map(range => this.m2p.asRange(range));
151
- }
152
- mapModelContentChange(change) {
153
- return {
154
- range: this.m2p.asRange(change.range),
155
- rangeLength: change.rangeLength,
156
- text: change.text
157
- };
158
- }
159
- get onDispose() {
160
- return this.toDispose.onDispose;
161
- }
162
- get onDocumentContentChanged() {
163
- return this.onDocumentContentChangedEmitter.event;
164
- }
165
- get isReadonly() {
166
- return this.document.isReadonly();
167
- }
168
- get cursor() {
169
- const { lineNumber, column } = this.editor.getPosition();
170
- return this.m2p.asPosition(lineNumber, column);
171
- }
172
- set cursor(cursor) {
173
- const position = this.p2m.asPosition(cursor);
174
- this.editor.setPosition(position);
175
- }
176
- get onCursorPositionChanged() {
177
- return this.onCursorPositionChangedEmitter.event;
178
- }
179
- get selection() {
180
- return this.m2p.asRange(this.editor.getSelection());
181
- }
182
- set selection(selection) {
183
- const range = this.p2m.asRange(selection);
184
- this.editor.setSelection(range);
185
- }
186
- get onSelectionChanged() {
187
- return this.onSelectionChangedEmitter.event;
188
- }
189
- get onScrollChanged() {
190
- return this.onScrollChangedEmitter.event;
191
- }
192
- revealPosition(raw, options = { vertical: 'center' }) {
193
- const position = this.p2m.asPosition(raw);
194
- switch (options.vertical) {
195
- case 'auto':
196
- this.editor.revealPosition(position);
197
- break;
198
- case 'center':
199
- this.editor.revealPositionInCenter(position);
200
- break;
201
- case 'centerIfOutsideViewport':
202
- this.editor.revealPositionInCenterIfOutsideViewport(position);
203
- break;
204
- }
205
- }
206
- revealRange(raw, options = { at: 'center' }) {
207
- const range = this.p2m.asRange(raw);
208
- switch (options.at) {
209
- case 'top':
210
- this.editor.revealRangeAtTop(range);
211
- break;
212
- case 'center':
213
- this.editor.revealRangeInCenter(range);
214
- break;
215
- case 'centerIfOutsideViewport':
216
- this.editor.revealRangeInCenterIfOutsideViewport(range);
217
- break;
218
- case 'auto':
219
- this.editor.revealRange(range);
220
- break;
221
- }
222
- }
223
- focus() {
224
- /**
225
- * `this.editor.focus` forcefully changes the focus editor state,
226
- * regardless whether the textarea actually received the focus.
227
- * It could lead to issues like https://github.com/eclipse-theia/theia/issues/7902
228
- * Instead we focus the underlying textarea.
229
- */
230
- const node = this.editor.getDomNode();
231
- if (node) {
232
- const textarea = node.querySelector('textarea');
233
- textarea.focus();
234
- }
235
- }
236
- blur() {
237
- const node = this.editor.getDomNode();
238
- if (node) {
239
- const textarea = node.querySelector('textarea');
240
- textarea.blur();
241
- }
242
- }
243
- isFocused({ strict } = { strict: false }) {
244
- if (!this.editor.hasTextFocus()) {
245
- return false;
246
- }
247
- if (strict) {
248
- return !this.isSuggestWidgetVisible() && !this.isFindWidgetVisible() && !this.isRenameInputVisible();
249
- }
250
- return true;
251
- }
252
- get onFocusChanged() {
253
- return this.onFocusChangedEmitter.event;
254
- }
255
- get onMouseDown() {
256
- return this.onMouseDownEmitter.event;
257
- }
258
- /**
259
- * `true` if the suggest widget is visible in the editor. Otherwise, `false`.
260
- */
261
- isSuggestWidgetVisible() {
262
- return this.contextKeyService.match('suggestWidgetVisible', this.editor.getDomNode() || this.node);
263
- }
264
- /**
265
- * `true` if the find (and replace) widget is visible in the editor. Otherwise, `false`.
266
- */
267
- isFindWidgetVisible() {
268
- return this.contextKeyService.match('findWidgetVisible', this.editor.getDomNode() || this.node);
269
- }
270
- /**
271
- * `true` if the name rename refactoring input HTML element is visible. Otherwise, `false`.
272
- */
273
- isRenameInputVisible() {
274
- return this.contextKeyService.match('renameInputVisible', this.editor.getDomNode() || this.node);
275
- }
276
- dispose() {
277
- this.toDispose.dispose();
278
- }
279
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
280
- trigger(source, handlerId, payload) {
281
- this.editor.trigger(source, handlerId, payload);
282
- }
283
- getControl() {
284
- return this.editor;
285
- }
286
- refresh() {
287
- this.autoresize();
288
- }
289
- resizeToFit() {
290
- this.autoresize();
291
- // eslint-disable-next-line no-null/no-null
292
- this.onResizeEmitter.fire(null);
293
- }
294
- setSize(dimension) {
295
- this.resize(dimension);
296
- this.onResizeEmitter.fire(dimension);
297
- }
298
- autoresize() {
299
- if (this.autoSizing) {
300
- // eslint-disable-next-line no-null/no-null
301
- this.resize(null);
302
- }
303
- }
304
- resize(dimension) {
305
- if (this.node) {
306
- const layoutSize = this.computeLayoutSize(this.node, dimension);
307
- this.editor.layout(layoutSize);
308
- }
309
- }
310
- computeLayoutSize(hostNode, dimension) {
311
- if (dimension && dimension.width >= 0 && dimension.height >= 0) {
312
- return dimension;
313
- }
314
- const boxSizing = domutils_1.ElementExt.boxSizing(hostNode);
315
- const width = (!dimension || dimension.width < 0) ?
316
- this.getWidth(hostNode, boxSizing) :
317
- dimension.width;
318
- const height = (!dimension || dimension.height < 0) ?
319
- this.getHeight(hostNode, boxSizing) :
320
- dimension.height;
321
- return { width, height };
322
- }
323
- getWidth(hostNode, boxSizing) {
324
- return hostNode.offsetWidth - boxSizing.horizontalSum;
325
- }
326
- getHeight(hostNode, boxSizing) {
327
- if (!this.autoSizing) {
328
- return hostNode.offsetHeight - boxSizing.verticalSum;
329
- }
330
- const lineHeight = this.editor.getOption(monaco.editor.EditorOption.lineHeight);
331
- const lineCount = this.editor.getModel().getLineCount();
332
- const contentHeight = lineHeight * lineCount;
333
- const horizontalScrollbarHeight = this.editor.getLayoutInfo().horizontalScrollbarHeight;
334
- const editorHeight = contentHeight + horizontalScrollbarHeight;
335
- if (this.minHeight >= 0) {
336
- const minHeight = lineHeight * this.minHeight + horizontalScrollbarHeight;
337
- if (editorHeight < minHeight) {
338
- return minHeight;
339
- }
340
- }
341
- if (this.maxHeight >= 0) {
342
- const maxHeight = lineHeight * this.maxHeight + horizontalScrollbarHeight;
343
- return Math.min(maxHeight, editorHeight);
344
- }
345
- return editorHeight;
346
- }
347
- isActionSupported(id) {
348
- const action = this.editor.getAction(id);
349
- return !!action && action.isSupported();
350
- }
351
- async runAction(id) {
352
- const action = this.editor.getAction(id);
353
- if (action && action.isSupported()) {
354
- await action.run();
355
- }
356
- }
357
- deltaDecorations(params) {
358
- const oldDecorations = params.oldDecorations;
359
- const newDecorations = this.toDeltaDecorations(params);
360
- return this.editor.deltaDecorations(oldDecorations, newDecorations);
361
- }
362
- toDeltaDecorations(params) {
363
- return params.newDecorations.map(({ options: theiaOptions, range }) => {
364
- const options = Object.assign(Object.assign({}, theiaOptions), { hoverMessage: this.fromStringToMarkdownString(theiaOptions.hoverMessage), glyphMarginHoverMessage: this.fromStringToMarkdownString(theiaOptions.glyphMarginHoverMessage) });
365
- return {
366
- options,
367
- range: this.p2m.asRange(range),
368
- };
369
- });
370
- }
371
- fromStringToMarkdownString(hoverMessage) {
372
- if (typeof hoverMessage === 'string') {
373
- return { value: hoverMessage };
374
- }
375
- return hoverMessage;
376
- }
377
- fromMarkdownToString(maybeMarkdown) {
378
- if (!maybeMarkdown) {
379
- return undefined;
380
- }
381
- if (typeof maybeMarkdown === 'string') {
382
- return maybeMarkdown;
383
- }
384
- if (Array.isArray(maybeMarkdown)) {
385
- return maybeMarkdown.map(({ value }) => value).join('\n');
386
- }
387
- return maybeMarkdown.value;
388
- }
389
- getLinesDecorations(startLineNumber, endLineNumber) {
390
- const toPosition = (line) => this.p2m.asPosition({ line, character: 0 });
391
- const start = toPosition(startLineNumber).lineNumber;
392
- const end = toPosition(endLineNumber).lineNumber;
393
- return this.editor
394
- .getModel()
395
- .getLinesDecorations(start, end)
396
- .map(this.toEditorDecoration.bind(this));
397
- }
398
- toEditorDecoration(decoration) {
399
- const range = this.m2p.asRange(decoration.range);
400
- const { id, options: monacoOptions } = decoration;
401
- const options = Object.assign(Object.assign({}, monacoOptions), { hoverMessage: this.fromMarkdownToString(monacoOptions.hoverMessage), glyphMarginHoverMessage: this.fromMarkdownToString(monacoOptions.hoverMessage) });
402
- return {
403
- options: (0, common_1.nullToUndefined)(options),
404
- range,
405
- id
406
- };
407
- }
408
- getVisibleColumn(position) {
409
- return this.editor.getVisibleColumnFromPosition(this.p2m.asPosition(position));
410
- }
411
- async replaceText(params) {
412
- const edits = params.replaceOperations.map(param => {
413
- const range = monaco.Range.fromPositions(this.p2m.asPosition(param.range.start), this.p2m.asPosition(param.range.end));
414
- return {
415
- forceMoveMarkers: true,
416
- identifier: {
417
- major: range.startLineNumber,
418
- minor: range.startColumn
419
- },
420
- range,
421
- text: param.text
422
- };
423
- });
424
- return this.editor.executeEdits(params.source, edits);
425
- }
426
- executeEdits(edits) {
427
- return this.editor.executeEdits('MonacoEditor', this.p2m.asTextEdits(edits));
428
- }
429
- storeViewState() {
430
- return this.editor.saveViewState();
431
- }
432
- restoreViewState(state) {
433
- this.editor.restoreViewState(state);
434
- }
435
- get languageAutoDetected() {
436
- return this._languageAutoDetected;
437
- }
438
- async detectLanguage() {
439
- const languageService = standaloneServices_1.StandaloneServices.get(language_1.ILanguageService);
440
- const firstLine = this.document.textEditorModel.getLineContent(1);
441
- const model = this.getControl().getModel();
442
- const language = languageService.createByFilepathOrFirstLine(model && model.uri, firstLine);
443
- this.setLanguage(language.languageId);
444
- this._languageAutoDetected = true;
445
- }
446
- setLanguage(languageId) {
447
- for (const document of this.documents) {
448
- monaco.editor.setModelLanguage(document.textEditorModel, languageId);
449
- }
450
- }
451
- fireLanguageChanged(languageId) {
452
- this._languageAutoDetected = false;
453
- this.onLanguageChangedEmitter.fire(languageId);
454
- }
455
- getResourceUri() {
456
- return this.uri;
457
- }
458
- createMoveToUri(resourceUri) {
459
- return this.uri.withPath(resourceUri.path);
460
- }
461
- }
462
- exports.MonacoEditor = MonacoEditor;
463
- (function (MonacoEditor) {
464
- function getAll(manager) {
465
- return manager.all.map(e => get(e)).filter(e => !!e);
466
- }
467
- MonacoEditor.getAll = getAll;
468
- function getCurrent(manager) {
469
- return get(manager.currentEditor);
470
- }
471
- MonacoEditor.getCurrent = getCurrent;
472
- function getActive(manager) {
473
- return get(manager.activeEditor);
474
- }
475
- MonacoEditor.getActive = getActive;
476
- function get(editorWidget) {
477
- if (editorWidget && editorWidget.editor instanceof MonacoEditor) {
478
- return editorWidget.editor;
479
- }
480
- return undefined;
481
- }
482
- MonacoEditor.get = get;
483
- function findByDocument(manager, document) {
484
- return getAll(manager).filter(candidate => candidate.documents.has(document));
485
- }
486
- MonacoEditor.findByDocument = findByDocument;
487
- function getWidgetFor(manager, control) {
488
- if (!control) {
489
- return undefined;
490
- }
491
- return manager.all.find(widget => {
492
- const candidate = get(widget);
493
- return candidate && candidate.getControl() === control;
494
- });
495
- }
496
- MonacoEditor.getWidgetFor = getWidgetFor;
497
- })(MonacoEditor = exports.MonacoEditor || (exports.MonacoEditor = {}));
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2018 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
27
+ return function (target, key) { decorator(target, key, paramIndex); }
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.MonacoEditor = exports.MonacoEditorServices = void 0;
31
+ const inversify_1 = require("@theia/core/shared/inversify");
32
+ const domutils_1 = require("@theia/core/shared/@phosphor/domutils");
33
+ const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
34
+ const common_1 = require("@theia/core/lib/common");
35
+ const monaco_to_protocol_converter_1 = require("./monaco-to-protocol-converter");
36
+ const protocol_to_monaco_converter_1 = require("./protocol-to-monaco-converter");
37
+ const encodings_1 = require("@theia/core/lib/common/encodings");
38
+ const monaco = require("@theia/monaco-editor-core");
39
+ const standaloneServices_1 = require("@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices");
40
+ const language_1 = require("@theia/monaco-editor-core/esm/vs/editor/common/languages/language");
41
+ const serviceCollection_1 = require("@theia/monaco-editor-core/esm/vs/platform/instantiation/common/serviceCollection");
42
+ const standaloneCodeEditor_1 = require("@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor");
43
+ let MonacoEditorServices = class MonacoEditorServices {
44
+ constructor(services) {
45
+ Object.assign(this, services);
46
+ }
47
+ };
48
+ __decorate([
49
+ (0, inversify_1.inject)(monaco_to_protocol_converter_1.MonacoToProtocolConverter),
50
+ __metadata("design:type", monaco_to_protocol_converter_1.MonacoToProtocolConverter)
51
+ ], MonacoEditorServices.prototype, "m2p", void 0);
52
+ __decorate([
53
+ (0, inversify_1.inject)(protocol_to_monaco_converter_1.ProtocolToMonacoConverter),
54
+ __metadata("design:type", protocol_to_monaco_converter_1.ProtocolToMonacoConverter)
55
+ ], MonacoEditorServices.prototype, "p2m", void 0);
56
+ __decorate([
57
+ (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
58
+ __metadata("design:type", Object)
59
+ ], MonacoEditorServices.prototype, "contextKeyService", void 0);
60
+ MonacoEditorServices = __decorate([
61
+ (0, inversify_1.injectable)(),
62
+ __param(0, (0, inversify_1.unmanaged)()),
63
+ __metadata("design:paramtypes", [MonacoEditorServices])
64
+ ], MonacoEditorServices);
65
+ exports.MonacoEditorServices = MonacoEditorServices;
66
+ class MonacoEditor extends MonacoEditorServices {
67
+ constructor(uri, document, node, services, options, override) {
68
+ super(services);
69
+ this.uri = uri;
70
+ this.document = document;
71
+ this.node = node;
72
+ this.toDispose = new common_1.DisposableCollection();
73
+ this.onCursorPositionChangedEmitter = new common_1.Emitter();
74
+ this.onSelectionChangedEmitter = new common_1.Emitter();
75
+ this.onFocusChangedEmitter = new common_1.Emitter();
76
+ this.onDocumentContentChangedEmitter = new common_1.Emitter();
77
+ this.onMouseDownEmitter = new common_1.Emitter();
78
+ this.onLanguageChangedEmitter = new common_1.Emitter();
79
+ this.onLanguageChanged = this.onLanguageChangedEmitter.event;
80
+ this.onScrollChangedEmitter = new common_1.Emitter();
81
+ this.onEncodingChanged = this.document.onDidChangeEncoding;
82
+ this.onResizeEmitter = new common_1.Emitter();
83
+ this.onDidResize = this.onResizeEmitter.event;
84
+ this.documents = new Set();
85
+ /* `true` because it is derived from an URI during the instantiation */
86
+ this._languageAutoDetected = true;
87
+ this.toDispose.pushAll([
88
+ this.onCursorPositionChangedEmitter,
89
+ this.onSelectionChangedEmitter,
90
+ this.onFocusChangedEmitter,
91
+ this.onDocumentContentChangedEmitter,
92
+ this.onMouseDownEmitter,
93
+ this.onLanguageChangedEmitter,
94
+ this.onScrollChangedEmitter
95
+ ]);
96
+ this.documents.add(document);
97
+ this.autoSizing = options && options.autoSizing !== undefined ? options.autoSizing : false;
98
+ this.minHeight = options && options.minHeight !== undefined ? options.minHeight : -1;
99
+ this.maxHeight = options && options.maxHeight !== undefined ? options.maxHeight : -1;
100
+ this.toDispose.push(this.create(options, override));
101
+ this.addHandlers(this.editor);
102
+ }
103
+ getEncoding() {
104
+ return this.document.getEncoding() || encodings_1.UTF8;
105
+ }
106
+ setEncoding(encoding, mode) {
107
+ return this.document.setEncoding(encoding, mode);
108
+ }
109
+ create(options, override) {
110
+ const combinedOptions = Object.assign(Object.assign({}, options), { lightbulb: { enabled: true }, fixedOverflowWidgets: true, scrollbar: Object.assign({ useShadows: false, verticalHasArrows: false, horizontalHasArrows: false, verticalScrollbarSize: 10, horizontalScrollbarSize: 10 }, options === null || options === void 0 ? void 0 : options.scrollbar) });
111
+ const instantiator = this.getInstantiatorWithOverrides(override);
112
+ /**
113
+ * @monaco-uplift. Should be guaranteed to work.
114
+ * Incomparable enums prevent TypeScript from believing that public IStandaloneCodeEditor is satisfied by private StandaloneCodeEditor
115
+ */
116
+ return this.editor = instantiator.createInstance(standaloneCodeEditor_1.StandaloneEditor, this.node, combinedOptions);
117
+ }
118
+ getInstantiatorWithOverrides(override) {
119
+ const instantiator = standaloneServices_1.StandaloneServices.initialize({});
120
+ if (override) {
121
+ const overrideServices = new serviceCollection_1.ServiceCollection(...override);
122
+ return instantiator.createChild(overrideServices);
123
+ }
124
+ return instantiator;
125
+ }
126
+ addHandlers(codeEditor) {
127
+ this.toDispose.push(codeEditor.onDidChangeModelLanguage(e => this.fireLanguageChanged(e.newLanguage)));
128
+ this.toDispose.push(codeEditor.onDidChangeConfiguration(() => this.refresh()));
129
+ this.toDispose.push(codeEditor.onDidChangeModel(() => this.refresh()));
130
+ this.toDispose.push(codeEditor.onDidChangeModelContent(e => {
131
+ this.refresh();
132
+ this.onDocumentContentChangedEmitter.fire({ document: this.document, contentChanges: e.changes.map(this.mapModelContentChange.bind(this)) });
133
+ }));
134
+ this.toDispose.push(codeEditor.onDidChangeCursorPosition(() => this.onCursorPositionChangedEmitter.fire(this.cursor)));
135
+ this.toDispose.push(codeEditor.onDidChangeCursorSelection(() => this.onSelectionChangedEmitter.fire(this.selection)));
136
+ this.toDispose.push(codeEditor.onDidFocusEditorText(() => this.onFocusChangedEmitter.fire(this.isFocused())));
137
+ this.toDispose.push(codeEditor.onDidBlurEditorText(() => this.onFocusChangedEmitter.fire(this.isFocused())));
138
+ this.toDispose.push(codeEditor.onMouseDown(e => {
139
+ const { element, position, range } = e.target;
140
+ this.onMouseDownEmitter.fire({
141
+ target: Object.assign(Object.assign({}, e.target), { element: element || undefined, mouseColumn: this.m2p.asPosition(undefined, e.target.mouseColumn).character, range: range && this.m2p.asRange(range) || undefined, position: position && this.m2p.asPosition(position.lineNumber, position.column) || undefined, detail: e.target.detail || {} }),
142
+ event: e.event.browserEvent
143
+ });
144
+ }));
145
+ this.toDispose.push(codeEditor.onDidScrollChange(e => {
146
+ this.onScrollChangedEmitter.fire(undefined);
147
+ }));
148
+ }
149
+ getVisibleRanges() {
150
+ return this.editor.getVisibleRanges().map(range => this.m2p.asRange(range));
151
+ }
152
+ mapModelContentChange(change) {
153
+ return {
154
+ range: this.m2p.asRange(change.range),
155
+ rangeLength: change.rangeLength,
156
+ text: change.text
157
+ };
158
+ }
159
+ get onDispose() {
160
+ return this.toDispose.onDispose;
161
+ }
162
+ get onDocumentContentChanged() {
163
+ return this.onDocumentContentChangedEmitter.event;
164
+ }
165
+ get isReadonly() {
166
+ return this.document.isReadonly();
167
+ }
168
+ get cursor() {
169
+ const { lineNumber, column } = this.editor.getPosition();
170
+ return this.m2p.asPosition(lineNumber, column);
171
+ }
172
+ set cursor(cursor) {
173
+ const position = this.p2m.asPosition(cursor);
174
+ this.editor.setPosition(position);
175
+ }
176
+ get onCursorPositionChanged() {
177
+ return this.onCursorPositionChangedEmitter.event;
178
+ }
179
+ get selection() {
180
+ return this.m2p.asRange(this.editor.getSelection());
181
+ }
182
+ set selection(selection) {
183
+ const range = this.p2m.asRange(selection);
184
+ this.editor.setSelection(range);
185
+ }
186
+ get onSelectionChanged() {
187
+ return this.onSelectionChangedEmitter.event;
188
+ }
189
+ get onScrollChanged() {
190
+ return this.onScrollChangedEmitter.event;
191
+ }
192
+ revealPosition(raw, options = { vertical: 'center' }) {
193
+ const position = this.p2m.asPosition(raw);
194
+ switch (options.vertical) {
195
+ case 'auto':
196
+ this.editor.revealPosition(position);
197
+ break;
198
+ case 'center':
199
+ this.editor.revealPositionInCenter(position);
200
+ break;
201
+ case 'centerIfOutsideViewport':
202
+ this.editor.revealPositionInCenterIfOutsideViewport(position);
203
+ break;
204
+ }
205
+ }
206
+ revealRange(raw, options = { at: 'center' }) {
207
+ const range = this.p2m.asRange(raw);
208
+ switch (options.at) {
209
+ case 'top':
210
+ this.editor.revealRangeAtTop(range);
211
+ break;
212
+ case 'center':
213
+ this.editor.revealRangeInCenter(range);
214
+ break;
215
+ case 'centerIfOutsideViewport':
216
+ this.editor.revealRangeInCenterIfOutsideViewport(range);
217
+ break;
218
+ case 'auto':
219
+ this.editor.revealRange(range);
220
+ break;
221
+ }
222
+ }
223
+ focus() {
224
+ /**
225
+ * `this.editor.focus` forcefully changes the focus editor state,
226
+ * regardless whether the textarea actually received the focus.
227
+ * It could lead to issues like https://github.com/eclipse-theia/theia/issues/7902
228
+ * Instead we focus the underlying textarea.
229
+ */
230
+ const node = this.editor.getDomNode();
231
+ if (node) {
232
+ const textarea = node.querySelector('textarea');
233
+ textarea.focus();
234
+ }
235
+ }
236
+ blur() {
237
+ const node = this.editor.getDomNode();
238
+ if (node) {
239
+ const textarea = node.querySelector('textarea');
240
+ textarea.blur();
241
+ }
242
+ }
243
+ isFocused({ strict } = { strict: false }) {
244
+ if (!this.editor.hasTextFocus()) {
245
+ return false;
246
+ }
247
+ if (strict) {
248
+ return !this.isSuggestWidgetVisible() && !this.isFindWidgetVisible() && !this.isRenameInputVisible();
249
+ }
250
+ return true;
251
+ }
252
+ get onFocusChanged() {
253
+ return this.onFocusChangedEmitter.event;
254
+ }
255
+ get onMouseDown() {
256
+ return this.onMouseDownEmitter.event;
257
+ }
258
+ /**
259
+ * `true` if the suggest widget is visible in the editor. Otherwise, `false`.
260
+ */
261
+ isSuggestWidgetVisible() {
262
+ return this.contextKeyService.match('suggestWidgetVisible', this.editor.getDomNode() || this.node);
263
+ }
264
+ /**
265
+ * `true` if the find (and replace) widget is visible in the editor. Otherwise, `false`.
266
+ */
267
+ isFindWidgetVisible() {
268
+ return this.contextKeyService.match('findWidgetVisible', this.editor.getDomNode() || this.node);
269
+ }
270
+ /**
271
+ * `true` if the name rename refactoring input HTML element is visible. Otherwise, `false`.
272
+ */
273
+ isRenameInputVisible() {
274
+ return this.contextKeyService.match('renameInputVisible', this.editor.getDomNode() || this.node);
275
+ }
276
+ dispose() {
277
+ this.toDispose.dispose();
278
+ }
279
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
280
+ trigger(source, handlerId, payload) {
281
+ this.editor.trigger(source, handlerId, payload);
282
+ }
283
+ getControl() {
284
+ return this.editor;
285
+ }
286
+ refresh() {
287
+ this.autoresize();
288
+ }
289
+ resizeToFit() {
290
+ this.autoresize();
291
+ // eslint-disable-next-line no-null/no-null
292
+ this.onResizeEmitter.fire(null);
293
+ }
294
+ setSize(dimension) {
295
+ this.resize(dimension);
296
+ this.onResizeEmitter.fire(dimension);
297
+ }
298
+ autoresize() {
299
+ if (this.autoSizing) {
300
+ // eslint-disable-next-line no-null/no-null
301
+ this.resize(null);
302
+ }
303
+ }
304
+ resize(dimension) {
305
+ if (this.node) {
306
+ const layoutSize = this.computeLayoutSize(this.node, dimension);
307
+ this.editor.layout(layoutSize);
308
+ }
309
+ }
310
+ computeLayoutSize(hostNode, dimension) {
311
+ if (dimension && dimension.width >= 0 && dimension.height >= 0) {
312
+ return dimension;
313
+ }
314
+ const boxSizing = domutils_1.ElementExt.boxSizing(hostNode);
315
+ const width = (!dimension || dimension.width < 0) ?
316
+ this.getWidth(hostNode, boxSizing) :
317
+ dimension.width;
318
+ const height = (!dimension || dimension.height < 0) ?
319
+ this.getHeight(hostNode, boxSizing) :
320
+ dimension.height;
321
+ return { width, height };
322
+ }
323
+ getWidth(hostNode, boxSizing) {
324
+ return hostNode.offsetWidth - boxSizing.horizontalSum;
325
+ }
326
+ getHeight(hostNode, boxSizing) {
327
+ if (!this.autoSizing) {
328
+ return hostNode.offsetHeight - boxSizing.verticalSum;
329
+ }
330
+ const lineHeight = this.editor.getOption(monaco.editor.EditorOption.lineHeight);
331
+ const lineCount = this.editor.getModel().getLineCount();
332
+ const contentHeight = lineHeight * lineCount;
333
+ const horizontalScrollbarHeight = this.editor.getLayoutInfo().horizontalScrollbarHeight;
334
+ const editorHeight = contentHeight + horizontalScrollbarHeight;
335
+ if (this.minHeight >= 0) {
336
+ const minHeight = lineHeight * this.minHeight + horizontalScrollbarHeight;
337
+ if (editorHeight < minHeight) {
338
+ return minHeight;
339
+ }
340
+ }
341
+ if (this.maxHeight >= 0) {
342
+ const maxHeight = lineHeight * this.maxHeight + horizontalScrollbarHeight;
343
+ return Math.min(maxHeight, editorHeight);
344
+ }
345
+ return editorHeight;
346
+ }
347
+ isActionSupported(id) {
348
+ const action = this.editor.getAction(id);
349
+ return !!action && action.isSupported();
350
+ }
351
+ async runAction(id) {
352
+ const action = this.editor.getAction(id);
353
+ if (action && action.isSupported()) {
354
+ await action.run();
355
+ }
356
+ }
357
+ deltaDecorations(params) {
358
+ const oldDecorations = params.oldDecorations;
359
+ const newDecorations = this.toDeltaDecorations(params);
360
+ return this.editor.deltaDecorations(oldDecorations, newDecorations);
361
+ }
362
+ toDeltaDecorations(params) {
363
+ return params.newDecorations.map(({ options: theiaOptions, range }) => {
364
+ const options = Object.assign(Object.assign({}, theiaOptions), { hoverMessage: this.fromStringToMarkdownString(theiaOptions.hoverMessage), glyphMarginHoverMessage: this.fromStringToMarkdownString(theiaOptions.glyphMarginHoverMessage) });
365
+ return {
366
+ options,
367
+ range: this.p2m.asRange(range),
368
+ };
369
+ });
370
+ }
371
+ fromStringToMarkdownString(hoverMessage) {
372
+ if (typeof hoverMessage === 'string') {
373
+ return { value: hoverMessage };
374
+ }
375
+ return hoverMessage;
376
+ }
377
+ fromMarkdownToString(maybeMarkdown) {
378
+ if (!maybeMarkdown) {
379
+ return undefined;
380
+ }
381
+ if (typeof maybeMarkdown === 'string') {
382
+ return maybeMarkdown;
383
+ }
384
+ if (Array.isArray(maybeMarkdown)) {
385
+ return maybeMarkdown.map(({ value }) => value).join('\n');
386
+ }
387
+ return maybeMarkdown.value;
388
+ }
389
+ getLinesDecorations(startLineNumber, endLineNumber) {
390
+ const toPosition = (line) => this.p2m.asPosition({ line, character: 0 });
391
+ const start = toPosition(startLineNumber).lineNumber;
392
+ const end = toPosition(endLineNumber).lineNumber;
393
+ return this.editor
394
+ .getModel()
395
+ .getLinesDecorations(start, end)
396
+ .map(this.toEditorDecoration.bind(this));
397
+ }
398
+ toEditorDecoration(decoration) {
399
+ const range = this.m2p.asRange(decoration.range);
400
+ const { id, options: monacoOptions } = decoration;
401
+ const options = Object.assign(Object.assign({}, monacoOptions), { hoverMessage: this.fromMarkdownToString(monacoOptions.hoverMessage), glyphMarginHoverMessage: this.fromMarkdownToString(monacoOptions.hoverMessage) });
402
+ return {
403
+ options: (0, common_1.nullToUndefined)(options),
404
+ range,
405
+ id
406
+ };
407
+ }
408
+ getVisibleColumn(position) {
409
+ return this.editor.getVisibleColumnFromPosition(this.p2m.asPosition(position));
410
+ }
411
+ async replaceText(params) {
412
+ const edits = params.replaceOperations.map(param => {
413
+ const range = monaco.Range.fromPositions(this.p2m.asPosition(param.range.start), this.p2m.asPosition(param.range.end));
414
+ return {
415
+ forceMoveMarkers: true,
416
+ identifier: {
417
+ major: range.startLineNumber,
418
+ minor: range.startColumn
419
+ },
420
+ range,
421
+ text: param.text
422
+ };
423
+ });
424
+ return this.editor.executeEdits(params.source, edits);
425
+ }
426
+ executeEdits(edits) {
427
+ return this.editor.executeEdits('MonacoEditor', this.p2m.asTextEdits(edits));
428
+ }
429
+ storeViewState() {
430
+ return this.editor.saveViewState();
431
+ }
432
+ restoreViewState(state) {
433
+ this.editor.restoreViewState(state);
434
+ }
435
+ get languageAutoDetected() {
436
+ return this._languageAutoDetected;
437
+ }
438
+ async detectLanguage() {
439
+ const languageService = standaloneServices_1.StandaloneServices.get(language_1.ILanguageService);
440
+ const firstLine = this.document.textEditorModel.getLineContent(1);
441
+ const model = this.getControl().getModel();
442
+ const language = languageService.createByFilepathOrFirstLine(model && model.uri, firstLine);
443
+ this.setLanguage(language.languageId);
444
+ this._languageAutoDetected = true;
445
+ }
446
+ setLanguage(languageId) {
447
+ for (const document of this.documents) {
448
+ monaco.editor.setModelLanguage(document.textEditorModel, languageId);
449
+ }
450
+ }
451
+ fireLanguageChanged(languageId) {
452
+ this._languageAutoDetected = false;
453
+ this.onLanguageChangedEmitter.fire(languageId);
454
+ }
455
+ getResourceUri() {
456
+ return this.uri;
457
+ }
458
+ createMoveToUri(resourceUri) {
459
+ return this.uri.withPath(resourceUri.path);
460
+ }
461
+ }
462
+ exports.MonacoEditor = MonacoEditor;
463
+ (function (MonacoEditor) {
464
+ function getAll(manager) {
465
+ return manager.all.map(e => get(e)).filter(e => !!e);
466
+ }
467
+ MonacoEditor.getAll = getAll;
468
+ function getCurrent(manager) {
469
+ return get(manager.currentEditor);
470
+ }
471
+ MonacoEditor.getCurrent = getCurrent;
472
+ function getActive(manager) {
473
+ return get(manager.activeEditor);
474
+ }
475
+ MonacoEditor.getActive = getActive;
476
+ function get(editorWidget) {
477
+ if (editorWidget && editorWidget.editor instanceof MonacoEditor) {
478
+ return editorWidget.editor;
479
+ }
480
+ return undefined;
481
+ }
482
+ MonacoEditor.get = get;
483
+ function findByDocument(manager, document) {
484
+ return getAll(manager).filter(candidate => candidate.documents.has(document));
485
+ }
486
+ MonacoEditor.findByDocument = findByDocument;
487
+ function getWidgetFor(manager, control) {
488
+ if (!control) {
489
+ return undefined;
490
+ }
491
+ return manager.all.find(widget => {
492
+ const candidate = get(widget);
493
+ return candidate && candidate.getControl() === control;
494
+ });
495
+ }
496
+ MonacoEditor.getWidgetFor = getWidgetFor;
497
+ })(MonacoEditor = exports.MonacoEditor || (exports.MonacoEditor = {}));
498
498
  //# sourceMappingURL=monaco-editor.js.map