@theia/monaco 1.45.1 → 1.46.0-next.72

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