@theia/editor 1.34.1 → 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 (100) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +30 -30
  3. package/lib/browser/decorations/editor-decoration-style.d.ts +8 -8
  4. package/lib/browser/decorations/editor-decoration-style.js +36 -36
  5. package/lib/browser/decorations/editor-decoration.d.ts +106 -106
  6. package/lib/browser/decorations/editor-decoration.js +37 -37
  7. package/lib/browser/decorations/editor-decorator.d.ts +6 -6
  8. package/lib/browser/decorations/editor-decorator.js +43 -43
  9. package/lib/browser/decorations/index.d.ts +3 -3
  10. package/lib/browser/decorations/index.js +30 -30
  11. package/lib/browser/diff-navigator.d.ts +10 -10
  12. package/lib/browser/diff-navigator.js +19 -19
  13. package/lib/browser/editor-command.d.ts +102 -102
  14. package/lib/browser/editor-command.js +426 -426
  15. package/lib/browser/editor-contribution.d.ts +26 -26
  16. package/lib/browser/editor-contribution.js +198 -198
  17. package/lib/browser/editor-frontend-module.d.ts +5 -5
  18. package/lib/browser/editor-frontend-module.js +74 -74
  19. package/lib/browser/editor-generated-preference-schema.d.ts +249 -249
  20. package/lib/browser/editor-generated-preference-schema.js +2316 -2316
  21. package/lib/browser/editor-keybinding-contexts.d.ts +35 -35
  22. package/lib/browser/editor-keybinding-contexts.js +98 -98
  23. package/lib/browser/editor-keybinding.d.ts +5 -5
  24. package/lib/browser/editor-keybinding.js +55 -55
  25. package/lib/browser/editor-manager.d.ts +113 -113
  26. package/lib/browser/editor-manager.js +412 -412
  27. package/lib/browser/editor-menu.d.ts +48 -48
  28. package/lib/browser/editor-menu.js +210 -210
  29. package/lib/browser/editor-navigation-contribution.d.ts +67 -67
  30. package/lib/browser/editor-navigation-contribution.js +331 -331
  31. package/lib/browser/editor-preferences.d.ts +40 -40
  32. package/lib/browser/editor-preferences.js +165 -165
  33. package/lib/browser/editor-variable-contribution.d.ts +8 -8
  34. package/lib/browser/editor-variable-contribution.js +64 -64
  35. package/lib/browser/editor-widget-factory.d.ts +17 -17
  36. package/lib/browser/editor-widget-factory.js +91 -91
  37. package/lib/browser/editor-widget.d.ts +20 -20
  38. package/lib/browser/editor-widget.js +87 -87
  39. package/lib/browser/editor.d.ts +293 -293
  40. package/lib/browser/editor.js +103 -103
  41. package/lib/browser/index.d.ts +10 -10
  42. package/lib/browser/index.js +37 -37
  43. package/lib/browser/language-status/editor-language-status-service.d.ts +77 -77
  44. package/lib/browser/language-status/editor-language-status-service.js +251 -251
  45. package/lib/browser/navigation/navigation-location-service.d.ts +103 -103
  46. package/lib/browser/navigation/navigation-location-service.js +281 -281
  47. package/lib/browser/navigation/navigation-location-service.spec.d.ts +1 -1
  48. package/lib/browser/navigation/navigation-location-service.spec.js +184 -184
  49. package/lib/browser/navigation/navigation-location-similarity.d.ts +15 -15
  50. package/lib/browser/navigation/navigation-location-similarity.js +62 -62
  51. package/lib/browser/navigation/navigation-location-similarity.spec.d.ts +1 -1
  52. package/lib/browser/navigation/navigation-location-similarity.spec.js +32 -32
  53. package/lib/browser/navigation/navigation-location-updater.d.ts +35 -35
  54. package/lib/browser/navigation/navigation-location-updater.js +210 -210
  55. package/lib/browser/navigation/navigation-location-updater.spec.d.ts +1 -1
  56. package/lib/browser/navigation/navigation-location-updater.spec.js +177 -177
  57. package/lib/browser/navigation/navigation-location.d.ts +191 -191
  58. package/lib/browser/navigation/navigation-location.js +300 -300
  59. package/lib/browser/navigation/test/mock-navigation-location-updater.d.ts +15 -15
  60. package/lib/browser/navigation/test/mock-navigation-location-updater.js +38 -38
  61. package/lib/browser/quick-editor-service.d.ts +16 -16
  62. package/lib/browser/quick-editor-service.js +109 -109
  63. package/lib/common/language-selector.d.ts +13 -13
  64. package/lib/common/language-selector.js +90 -90
  65. package/lib/package.spec.js +25 -25
  66. package/package.json +5 -5
  67. package/src/browser/decorations/editor-decoration-style.ts +41 -41
  68. package/src/browser/decorations/editor-decoration.ts +127 -127
  69. package/src/browser/decorations/editor-decorator.ts +36 -36
  70. package/src/browser/decorations/index.ts +19 -19
  71. package/src/browser/diff-navigator.ts +28 -28
  72. package/src/browser/editor-command.ts +414 -414
  73. package/src/browser/editor-contribution.ts +185 -185
  74. package/src/browser/editor-frontend-module.ts +85 -85
  75. package/src/browser/editor-generated-preference-schema.ts +2539 -2539
  76. package/src/browser/editor-keybinding-contexts.ts +87 -87
  77. package/src/browser/editor-keybinding.ts +55 -55
  78. package/src/browser/editor-manager.ts +429 -429
  79. package/src/browser/editor-menu.ts +224 -224
  80. package/src/browser/editor-navigation-contribution.ts +331 -331
  81. package/src/browser/editor-preferences.ts +220 -220
  82. package/src/browser/editor-variable-contribution.ts +54 -54
  83. package/src/browser/editor-widget-factory.ts +82 -82
  84. package/src/browser/editor-widget.ts +98 -98
  85. package/src/browser/editor.ts +358 -358
  86. package/src/browser/index.ts +26 -26
  87. package/src/browser/language-status/editor-language-status-service.ts +271 -271
  88. package/src/browser/language-status/editor-language-status.css +98 -98
  89. package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
  90. package/src/browser/navigation/navigation-location-service.ts +284 -284
  91. package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
  92. package/src/browser/navigation/navigation-location-similarity.ts +58 -58
  93. package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
  94. package/src/browser/navigation/navigation-location-updater.ts +220 -220
  95. package/src/browser/navigation/navigation-location.ts +418 -418
  96. package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
  97. package/src/browser/quick-editor-service.ts +94 -94
  98. package/src/browser/style/index.css +19 -19
  99. package/src/common/language-selector.ts +104 -104
  100. package/src/package.spec.ts +28 -28
@@ -1,413 +1,413 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2017 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
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.ActiveEditorAccess = exports.CurrentEditorAccess = exports.EditorAccess = exports.EditorManager = void 0;
28
- const inversify_1 = require("@theia/core/shared/inversify");
29
- const common_1 = require("@theia/core/lib/common");
30
- const browser_1 = require("@theia/core/lib/browser");
31
- const editor_widget_1 = require("./editor-widget");
32
- const editor_1 = require("./editor");
33
- const editor_widget_factory_1 = require("./editor-widget-factory");
34
- let EditorManager = class EditorManager extends browser_1.NavigatableWidgetOpenHandler {
35
- constructor() {
36
- super(...arguments);
37
- this.id = editor_widget_factory_1.EditorWidgetFactory.ID;
38
- this.label = 'Code Editor';
39
- this.editorCounters = new Map();
40
- this.onActiveEditorChangedEmitter = new common_1.Emitter();
41
- /**
42
- * Emit when the active editor is changed.
43
- */
44
- this.onActiveEditorChanged = this.onActiveEditorChangedEmitter.event;
45
- this.onCurrentEditorChangedEmitter = new common_1.Emitter();
46
- /**
47
- * Emit when the current editor is changed.
48
- */
49
- this.onCurrentEditorChanged = this.onCurrentEditorChangedEmitter.event;
50
- this.recentlyVisibleIds = [];
51
- }
52
- init() {
53
- super.init();
54
- this.shell.onDidChangeActiveWidget(() => this.updateActiveEditor());
55
- this.shell.onDidChangeCurrentWidget(() => this.updateCurrentEditor());
56
- this.onCreated(widget => {
57
- widget.onDidChangeVisibility(() => {
58
- if (widget.isVisible) {
59
- this.addRecentlyVisible(widget);
60
- }
61
- this.updateCurrentEditor();
62
- });
63
- this.checkCounterForWidget(widget);
64
- widget.disposed.connect(() => {
65
- this.removeFromCounter(widget);
66
- this.removeRecentlyVisible(widget);
67
- this.updateCurrentEditor();
68
- });
69
- });
70
- for (const widget of this.all) {
71
- if (widget.isVisible) {
72
- this.addRecentlyVisible(widget);
73
- }
74
- }
75
- this.updateCurrentEditor();
76
- }
77
- getByUri(uri, options) {
78
- return this.getWidget(uri, options);
79
- }
80
- getOrCreateByUri(uri, options) {
81
- return this.getOrCreateWidget(uri, options);
82
- }
83
- tryGetPendingWidget(uri, options) {
84
- const editorPromise = super.tryGetPendingWidget(uri, options);
85
- if (editorPromise) {
86
- // Reveal selection before attachment to manage nav stack. (https://github.com/eclipse-theia/theia/issues/8955)
87
- if (!(editorPromise instanceof browser_1.Widget)) {
88
- editorPromise.then(editor => this.revealSelection(editor, options, uri));
89
- }
90
- else {
91
- this.revealSelection(editorPromise, options);
92
- }
93
- }
94
- return editorPromise;
95
- }
96
- async getWidget(uri, options) {
97
- const editor = await super.getWidget(uri, options);
98
- if (editor) {
99
- // Reveal selection before attachment to manage nav stack. (https://github.com/eclipse-theia/theia/issues/8955)
100
- this.revealSelection(editor, options, uri);
101
- }
102
- return editor;
103
- }
104
- async getOrCreateWidget(uri, options) {
105
- const editor = await super.getOrCreateWidget(uri, options);
106
- // Reveal selection before attachment to manage nav stack. (https://github.com/eclipse-theia/theia/issues/8955)
107
- this.revealSelection(editor, options, uri);
108
- return editor;
109
- }
110
- get recentlyVisible() {
111
- const id = this.recentlyVisibleIds[0];
112
- return id && this.all.find(w => w.id === id) || undefined;
113
- }
114
- addRecentlyVisible(widget) {
115
- this.removeRecentlyVisible(widget);
116
- this.recentlyVisibleIds.unshift(widget.id);
117
- }
118
- removeRecentlyVisible(widget) {
119
- const index = this.recentlyVisibleIds.indexOf(widget.id);
120
- if (index !== -1) {
121
- this.recentlyVisibleIds.splice(index, 1);
122
- }
123
- }
124
- /**
125
- * The active editor.
126
- * If there is an active editor (one that has focus), active and current are the same.
127
- */
128
- get activeEditor() {
129
- return this._activeEditor;
130
- }
131
- setActiveEditor(active) {
132
- if (this._activeEditor !== active) {
133
- this._activeEditor = active;
134
- this.onActiveEditorChangedEmitter.fire(this._activeEditor);
135
- }
136
- }
137
- updateActiveEditor() {
138
- const widget = this.shell.activeWidget;
139
- if (widget instanceof editor_widget_1.EditorWidget) {
140
- this.addRecentlyVisible(widget);
141
- this.setActiveEditor(widget);
142
- }
143
- else {
144
- this.setActiveEditor(undefined);
145
- }
146
- }
147
- /**
148
- * The most recently activated editor (which might not have the focus anymore, hence it is not active).
149
- * If no editor has focus, e.g. when a context menu is shown, the active editor is `undefined`, but current might be the editor that was active before the menu popped up.
150
- */
151
- get currentEditor() {
152
- return this._currentEditor;
153
- }
154
- setCurrentEditor(current) {
155
- if (this._currentEditor !== current) {
156
- this._currentEditor = current;
157
- this.onCurrentEditorChangedEmitter.fire(this._currentEditor);
158
- }
159
- }
160
- updateCurrentEditor() {
161
- const widget = this.shell.currentWidget;
162
- if (widget instanceof editor_widget_1.EditorWidget) {
163
- this.setCurrentEditor(widget);
164
- }
165
- else if (!this._currentEditor || !this._currentEditor.isVisible || this.currentEditor !== this.recentlyVisible) {
166
- this.setCurrentEditor(this.recentlyVisible);
167
- }
168
- }
169
- canHandle(uri, options) {
170
- return 100;
171
- }
172
- open(uri, options) {
173
- var _a;
174
- if ((options === null || options === void 0 ? void 0 : options.counter) === undefined) {
175
- const insertionOptions = this.shell.getInsertionOptions(options === null || options === void 0 ? void 0 : options.widgetOptions);
176
- // Definitely creating a new tabbar - no widget can match.
177
- if ((_a = insertionOptions.addOptions.mode) === null || _a === void 0 ? void 0 : _a.startsWith('split')) {
178
- return super.open(uri, Object.assign({ counter: this.createCounterForUri(uri) }, options));
179
- }
180
- // Check the target tabbar for an existing widget.
181
- const tabbar = insertionOptions.addOptions.ref && this.shell.getTabBarFor(insertionOptions.addOptions.ref);
182
- if (tabbar) {
183
- const currentUri = uri.toString();
184
- for (const title of tabbar.titles) {
185
- if (title.owner instanceof editor_widget_1.EditorWidget) {
186
- const { uri: otherWidgetUri, id } = this.extractIdFromWidget(title.owner);
187
- if (otherWidgetUri === currentUri) {
188
- return super.open(uri, Object.assign({ counter: id }, options));
189
- }
190
- }
191
- }
192
- }
193
- // Open a new widget.
194
- return super.open(uri, Object.assign({ counter: this.createCounterForUri(uri) }, options));
195
- }
196
- return super.open(uri, options);
197
- }
198
- /**
199
- * Opens an editor to the side of the current editor. Defaults to opening to the right.
200
- * To modify direction, pass options with `{widgetOptions: {mode: ...}}`
201
- */
202
- openToSide(uri, options) {
203
- const counter = this.createCounterForUri(uri);
204
- const splitOptions = Object.assign(Object.assign({ widgetOptions: { mode: 'split-right' } }, options), { counter });
205
- return this.open(uri, splitOptions);
206
- }
207
- revealSelection(widget, input, uri) {
208
- let inputSelection = input === null || input === void 0 ? void 0 : input.selection;
209
- if (!inputSelection && uri) {
210
- const match = /^L?(\d+)(?:,(\d+))?/.exec(uri.fragment);
211
- if (match) {
212
- // support file:///some/file.js#73,84
213
- // support file:///some/file.js#L73
214
- inputSelection = {
215
- start: {
216
- line: parseInt(match[1]) - 1,
217
- character: match[2] ? parseInt(match[2]) - 1 : 0
218
- }
219
- };
220
- }
221
- }
222
- if (inputSelection) {
223
- const editor = widget.editor;
224
- const selection = this.getSelection(widget, inputSelection);
225
- if (editor_1.Position.is(selection)) {
226
- editor.cursor = selection;
227
- editor.revealPosition(selection);
228
- }
229
- else if (editor_1.Range.is(selection)) {
230
- editor.cursor = selection.end;
231
- editor.selection = selection;
232
- editor.revealRange(selection);
233
- }
234
- }
235
- }
236
- getSelection(widget, selection) {
237
- const { start, end } = selection;
238
- if (editor_1.Position.is(start)) {
239
- if (editor_1.Position.is(end)) {
240
- return widget.editor.document.toValidRange({ start, end });
241
- }
242
- return widget.editor.document.toValidPosition(start);
243
- }
244
- const line = start && start.line !== undefined && start.line >= 0 ? start.line : undefined;
245
- if (line === undefined) {
246
- return undefined;
247
- }
248
- const character = start && start.character !== undefined && start.character >= 0 ? start.character : widget.editor.document.getLineMaxColumn(line);
249
- const endLine = end && end.line !== undefined && end.line >= 0 ? end.line : undefined;
250
- if (endLine === undefined) {
251
- return { line, character };
252
- }
253
- const endCharacter = end && end.character !== undefined && end.character >= 0 ? end.character : widget.editor.document.getLineMaxColumn(endLine);
254
- return {
255
- start: { line, character },
256
- end: { line: endLine, character: endCharacter }
257
- };
258
- }
259
- removeFromCounter(widget) {
260
- const { id, uri } = this.extractIdFromWidget(widget);
261
- if (uri && !Number.isNaN(id)) {
262
- let max = -Infinity;
263
- this.all.forEach(editor => {
264
- const candidateID = this.extractIdFromWidget(editor);
265
- if ((candidateID.uri === uri) && (candidateID.id > max)) {
266
- max = candidateID.id;
267
- }
268
- });
269
- if (max > -Infinity) {
270
- this.editorCounters.set(uri, max);
271
- }
272
- else {
273
- this.editorCounters.delete(uri);
274
- }
275
- }
276
- }
277
- extractIdFromWidget(widget) {
278
- const uri = widget.editor.uri.toString();
279
- const id = Number(widget.id.slice(widget.id.lastIndexOf(':') + 1));
280
- return { id, uri };
281
- }
282
- checkCounterForWidget(widget) {
283
- var _a;
284
- const { id, uri } = this.extractIdFromWidget(widget);
285
- const numericalId = Number(id);
286
- if (uri && !Number.isNaN(numericalId)) {
287
- const highestKnownId = (_a = this.editorCounters.get(uri)) !== null && _a !== void 0 ? _a : -Infinity;
288
- if (numericalId > highestKnownId) {
289
- this.editorCounters.set(uri, numericalId);
290
- }
291
- }
292
- }
293
- createCounterForUri(uri) {
294
- var _a;
295
- const identifier = uri.toString();
296
- const next = ((_a = this.editorCounters.get(identifier)) !== null && _a !== void 0 ? _a : 0) + 1;
297
- return next;
298
- }
299
- getCounterForUri(uri) {
300
- var _a;
301
- const idWithoutCounter = editor_widget_factory_1.EditorWidgetFactory.createID(uri);
302
- const counterOfMostRecentlyVisibleEditor = (_a = this.recentlyVisibleIds.find(id => id.startsWith(idWithoutCounter))) === null || _a === void 0 ? void 0 : _a.slice(idWithoutCounter.length + 1);
303
- return counterOfMostRecentlyVisibleEditor === undefined ? undefined : parseInt(counterOfMostRecentlyVisibleEditor);
304
- }
305
- getOrCreateCounterForUri(uri) {
306
- var _a;
307
- return (_a = this.getCounterForUri(uri)) !== null && _a !== void 0 ? _a : this.createCounterForUri(uri);
308
- }
309
- createWidgetOptions(uri, options) {
310
- var _a;
311
- const navigatableOptions = super.createWidgetOptions(uri, options);
312
- navigatableOptions.counter = (_a = options === null || options === void 0 ? void 0 : options.counter) !== null && _a !== void 0 ? _a : this.getOrCreateCounterForUri(uri);
313
- return navigatableOptions;
314
- }
315
- };
316
- __decorate([
317
- (0, inversify_1.postConstruct)(),
318
- __metadata("design:type", Function),
319
- __metadata("design:paramtypes", []),
320
- __metadata("design:returntype", void 0)
321
- ], EditorManager.prototype, "init", null);
322
- EditorManager = __decorate([
323
- (0, inversify_1.injectable)()
324
- ], EditorManager);
325
- exports.EditorManager = EditorManager;
326
- /**
327
- * Provides direct access to the underlying text editor.
328
- */
329
- let EditorAccess = class EditorAccess {
330
- /**
331
- * The URI of the underlying document from the editor.
332
- */
333
- get uri() {
334
- const editor = this.editor;
335
- if (editor) {
336
- return editor.uri.toString();
337
- }
338
- return undefined;
339
- }
340
- /**
341
- * The selection location from the text editor.
342
- */
343
- get selection() {
344
- const editor = this.editor;
345
- if (editor) {
346
- const uri = editor.uri.toString();
347
- const range = editor.selection;
348
- return {
349
- range,
350
- uri
351
- };
352
- }
353
- return undefined;
354
- }
355
- /**
356
- * The unique identifier of the language the current editor belongs to.
357
- */
358
- get languageId() {
359
- const editor = this.editor;
360
- if (editor) {
361
- return editor.document.languageId;
362
- }
363
- return undefined;
364
- }
365
- /**
366
- * The text editor.
367
- */
368
- get editor() {
369
- const editorWidget = this.editorWidget();
370
- if (editorWidget) {
371
- return editorWidget.editor;
372
- }
373
- return undefined;
374
- }
375
- };
376
- __decorate([
377
- (0, inversify_1.inject)(EditorManager),
378
- __metadata("design:type", EditorManager)
379
- ], EditorAccess.prototype, "editorManager", void 0);
380
- EditorAccess = __decorate([
381
- (0, inversify_1.injectable)()
382
- ], EditorAccess);
383
- exports.EditorAccess = EditorAccess;
384
- /**
385
- * Provides direct access to the currently active text editor.
386
- */
387
- let CurrentEditorAccess = class CurrentEditorAccess extends EditorAccess {
388
- editorWidget() {
389
- return this.editorManager.currentEditor;
390
- }
391
- };
392
- CurrentEditorAccess = __decorate([
393
- (0, inversify_1.injectable)()
394
- ], CurrentEditorAccess);
395
- exports.CurrentEditorAccess = CurrentEditorAccess;
396
- /**
397
- * Provides access to the active text editor.
398
- */
399
- let ActiveEditorAccess = class ActiveEditorAccess extends EditorAccess {
400
- editorWidget() {
401
- return this.editorManager.activeEditor;
402
- }
403
- };
404
- ActiveEditorAccess = __decorate([
405
- (0, inversify_1.injectable)()
406
- ], ActiveEditorAccess);
407
- exports.ActiveEditorAccess = ActiveEditorAccess;
408
- (function (EditorAccess) {
409
- EditorAccess.CURRENT = 'current-editor-access';
410
- EditorAccess.ACTIVE = 'active-editor-access';
411
- })(EditorAccess = exports.EditorAccess || (exports.EditorAccess = {}));
412
- exports.EditorAccess = EditorAccess;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2017 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
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.ActiveEditorAccess = exports.CurrentEditorAccess = exports.EditorAccess = exports.EditorManager = void 0;
28
+ const inversify_1 = require("@theia/core/shared/inversify");
29
+ const common_1 = require("@theia/core/lib/common");
30
+ const browser_1 = require("@theia/core/lib/browser");
31
+ const editor_widget_1 = require("./editor-widget");
32
+ const editor_1 = require("./editor");
33
+ const editor_widget_factory_1 = require("./editor-widget-factory");
34
+ let EditorManager = class EditorManager extends browser_1.NavigatableWidgetOpenHandler {
35
+ constructor() {
36
+ super(...arguments);
37
+ this.id = editor_widget_factory_1.EditorWidgetFactory.ID;
38
+ this.label = 'Code Editor';
39
+ this.editorCounters = new Map();
40
+ this.onActiveEditorChangedEmitter = new common_1.Emitter();
41
+ /**
42
+ * Emit when the active editor is changed.
43
+ */
44
+ this.onActiveEditorChanged = this.onActiveEditorChangedEmitter.event;
45
+ this.onCurrentEditorChangedEmitter = new common_1.Emitter();
46
+ /**
47
+ * Emit when the current editor is changed.
48
+ */
49
+ this.onCurrentEditorChanged = this.onCurrentEditorChangedEmitter.event;
50
+ this.recentlyVisibleIds = [];
51
+ }
52
+ init() {
53
+ super.init();
54
+ this.shell.onDidChangeActiveWidget(() => this.updateActiveEditor());
55
+ this.shell.onDidChangeCurrentWidget(() => this.updateCurrentEditor());
56
+ this.onCreated(widget => {
57
+ widget.onDidChangeVisibility(() => {
58
+ if (widget.isVisible) {
59
+ this.addRecentlyVisible(widget);
60
+ }
61
+ this.updateCurrentEditor();
62
+ });
63
+ this.checkCounterForWidget(widget);
64
+ widget.disposed.connect(() => {
65
+ this.removeFromCounter(widget);
66
+ this.removeRecentlyVisible(widget);
67
+ this.updateCurrentEditor();
68
+ });
69
+ });
70
+ for (const widget of this.all) {
71
+ if (widget.isVisible) {
72
+ this.addRecentlyVisible(widget);
73
+ }
74
+ }
75
+ this.updateCurrentEditor();
76
+ }
77
+ getByUri(uri, options) {
78
+ return this.getWidget(uri, options);
79
+ }
80
+ getOrCreateByUri(uri, options) {
81
+ return this.getOrCreateWidget(uri, options);
82
+ }
83
+ tryGetPendingWidget(uri, options) {
84
+ const editorPromise = super.tryGetPendingWidget(uri, options);
85
+ if (editorPromise) {
86
+ // Reveal selection before attachment to manage nav stack. (https://github.com/eclipse-theia/theia/issues/8955)
87
+ if (!(editorPromise instanceof browser_1.Widget)) {
88
+ editorPromise.then(editor => this.revealSelection(editor, options, uri));
89
+ }
90
+ else {
91
+ this.revealSelection(editorPromise, options);
92
+ }
93
+ }
94
+ return editorPromise;
95
+ }
96
+ async getWidget(uri, options) {
97
+ const editor = await super.getWidget(uri, options);
98
+ if (editor) {
99
+ // Reveal selection before attachment to manage nav stack. (https://github.com/eclipse-theia/theia/issues/8955)
100
+ this.revealSelection(editor, options, uri);
101
+ }
102
+ return editor;
103
+ }
104
+ async getOrCreateWidget(uri, options) {
105
+ const editor = await super.getOrCreateWidget(uri, options);
106
+ // Reveal selection before attachment to manage nav stack. (https://github.com/eclipse-theia/theia/issues/8955)
107
+ this.revealSelection(editor, options, uri);
108
+ return editor;
109
+ }
110
+ get recentlyVisible() {
111
+ const id = this.recentlyVisibleIds[0];
112
+ return id && this.all.find(w => w.id === id) || undefined;
113
+ }
114
+ addRecentlyVisible(widget) {
115
+ this.removeRecentlyVisible(widget);
116
+ this.recentlyVisibleIds.unshift(widget.id);
117
+ }
118
+ removeRecentlyVisible(widget) {
119
+ const index = this.recentlyVisibleIds.indexOf(widget.id);
120
+ if (index !== -1) {
121
+ this.recentlyVisibleIds.splice(index, 1);
122
+ }
123
+ }
124
+ /**
125
+ * The active editor.
126
+ * If there is an active editor (one that has focus), active and current are the same.
127
+ */
128
+ get activeEditor() {
129
+ return this._activeEditor;
130
+ }
131
+ setActiveEditor(active) {
132
+ if (this._activeEditor !== active) {
133
+ this._activeEditor = active;
134
+ this.onActiveEditorChangedEmitter.fire(this._activeEditor);
135
+ }
136
+ }
137
+ updateActiveEditor() {
138
+ const widget = this.shell.activeWidget;
139
+ if (widget instanceof editor_widget_1.EditorWidget) {
140
+ this.addRecentlyVisible(widget);
141
+ this.setActiveEditor(widget);
142
+ }
143
+ else {
144
+ this.setActiveEditor(undefined);
145
+ }
146
+ }
147
+ /**
148
+ * The most recently activated editor (which might not have the focus anymore, hence it is not active).
149
+ * If no editor has focus, e.g. when a context menu is shown, the active editor is `undefined`, but current might be the editor that was active before the menu popped up.
150
+ */
151
+ get currentEditor() {
152
+ return this._currentEditor;
153
+ }
154
+ setCurrentEditor(current) {
155
+ if (this._currentEditor !== current) {
156
+ this._currentEditor = current;
157
+ this.onCurrentEditorChangedEmitter.fire(this._currentEditor);
158
+ }
159
+ }
160
+ updateCurrentEditor() {
161
+ const widget = this.shell.currentWidget;
162
+ if (widget instanceof editor_widget_1.EditorWidget) {
163
+ this.setCurrentEditor(widget);
164
+ }
165
+ else if (!this._currentEditor || !this._currentEditor.isVisible || this.currentEditor !== this.recentlyVisible) {
166
+ this.setCurrentEditor(this.recentlyVisible);
167
+ }
168
+ }
169
+ canHandle(uri, options) {
170
+ return 100;
171
+ }
172
+ open(uri, options) {
173
+ var _a;
174
+ if ((options === null || options === void 0 ? void 0 : options.counter) === undefined) {
175
+ const insertionOptions = this.shell.getInsertionOptions(options === null || options === void 0 ? void 0 : options.widgetOptions);
176
+ // Definitely creating a new tabbar - no widget can match.
177
+ if ((_a = insertionOptions.addOptions.mode) === null || _a === void 0 ? void 0 : _a.startsWith('split')) {
178
+ return super.open(uri, Object.assign({ counter: this.createCounterForUri(uri) }, options));
179
+ }
180
+ // Check the target tabbar for an existing widget.
181
+ const tabbar = insertionOptions.addOptions.ref && this.shell.getTabBarFor(insertionOptions.addOptions.ref);
182
+ if (tabbar) {
183
+ const currentUri = uri.toString();
184
+ for (const title of tabbar.titles) {
185
+ if (title.owner instanceof editor_widget_1.EditorWidget) {
186
+ const { uri: otherWidgetUri, id } = this.extractIdFromWidget(title.owner);
187
+ if (otherWidgetUri === currentUri) {
188
+ return super.open(uri, Object.assign({ counter: id }, options));
189
+ }
190
+ }
191
+ }
192
+ }
193
+ // Open a new widget.
194
+ return super.open(uri, Object.assign({ counter: this.createCounterForUri(uri) }, options));
195
+ }
196
+ return super.open(uri, options);
197
+ }
198
+ /**
199
+ * Opens an editor to the side of the current editor. Defaults to opening to the right.
200
+ * To modify direction, pass options with `{widgetOptions: {mode: ...}}`
201
+ */
202
+ openToSide(uri, options) {
203
+ const counter = this.createCounterForUri(uri);
204
+ const splitOptions = Object.assign(Object.assign({ widgetOptions: { mode: 'split-right' } }, options), { counter });
205
+ return this.open(uri, splitOptions);
206
+ }
207
+ revealSelection(widget, input, uri) {
208
+ let inputSelection = input === null || input === void 0 ? void 0 : input.selection;
209
+ if (!inputSelection && uri) {
210
+ const match = /^L?(\d+)(?:,(\d+))?/.exec(uri.fragment);
211
+ if (match) {
212
+ // support file:///some/file.js#73,84
213
+ // support file:///some/file.js#L73
214
+ inputSelection = {
215
+ start: {
216
+ line: parseInt(match[1]) - 1,
217
+ character: match[2] ? parseInt(match[2]) - 1 : 0
218
+ }
219
+ };
220
+ }
221
+ }
222
+ if (inputSelection) {
223
+ const editor = widget.editor;
224
+ const selection = this.getSelection(widget, inputSelection);
225
+ if (editor_1.Position.is(selection)) {
226
+ editor.cursor = selection;
227
+ editor.revealPosition(selection);
228
+ }
229
+ else if (editor_1.Range.is(selection)) {
230
+ editor.cursor = selection.end;
231
+ editor.selection = selection;
232
+ editor.revealRange(selection);
233
+ }
234
+ }
235
+ }
236
+ getSelection(widget, selection) {
237
+ const { start, end } = selection;
238
+ if (editor_1.Position.is(start)) {
239
+ if (editor_1.Position.is(end)) {
240
+ return widget.editor.document.toValidRange({ start, end });
241
+ }
242
+ return widget.editor.document.toValidPosition(start);
243
+ }
244
+ const line = start && start.line !== undefined && start.line >= 0 ? start.line : undefined;
245
+ if (line === undefined) {
246
+ return undefined;
247
+ }
248
+ const character = start && start.character !== undefined && start.character >= 0 ? start.character : widget.editor.document.getLineMaxColumn(line);
249
+ const endLine = end && end.line !== undefined && end.line >= 0 ? end.line : undefined;
250
+ if (endLine === undefined) {
251
+ return { line, character };
252
+ }
253
+ const endCharacter = end && end.character !== undefined && end.character >= 0 ? end.character : widget.editor.document.getLineMaxColumn(endLine);
254
+ return {
255
+ start: { line, character },
256
+ end: { line: endLine, character: endCharacter }
257
+ };
258
+ }
259
+ removeFromCounter(widget) {
260
+ const { id, uri } = this.extractIdFromWidget(widget);
261
+ if (uri && !Number.isNaN(id)) {
262
+ let max = -Infinity;
263
+ this.all.forEach(editor => {
264
+ const candidateID = this.extractIdFromWidget(editor);
265
+ if ((candidateID.uri === uri) && (candidateID.id > max)) {
266
+ max = candidateID.id;
267
+ }
268
+ });
269
+ if (max > -Infinity) {
270
+ this.editorCounters.set(uri, max);
271
+ }
272
+ else {
273
+ this.editorCounters.delete(uri);
274
+ }
275
+ }
276
+ }
277
+ extractIdFromWidget(widget) {
278
+ const uri = widget.editor.uri.toString();
279
+ const id = Number(widget.id.slice(widget.id.lastIndexOf(':') + 1));
280
+ return { id, uri };
281
+ }
282
+ checkCounterForWidget(widget) {
283
+ var _a;
284
+ const { id, uri } = this.extractIdFromWidget(widget);
285
+ const numericalId = Number(id);
286
+ if (uri && !Number.isNaN(numericalId)) {
287
+ const highestKnownId = (_a = this.editorCounters.get(uri)) !== null && _a !== void 0 ? _a : -Infinity;
288
+ if (numericalId > highestKnownId) {
289
+ this.editorCounters.set(uri, numericalId);
290
+ }
291
+ }
292
+ }
293
+ createCounterForUri(uri) {
294
+ var _a;
295
+ const identifier = uri.toString();
296
+ const next = ((_a = this.editorCounters.get(identifier)) !== null && _a !== void 0 ? _a : 0) + 1;
297
+ return next;
298
+ }
299
+ getCounterForUri(uri) {
300
+ var _a;
301
+ const idWithoutCounter = editor_widget_factory_1.EditorWidgetFactory.createID(uri);
302
+ const counterOfMostRecentlyVisibleEditor = (_a = this.recentlyVisibleIds.find(id => id.startsWith(idWithoutCounter))) === null || _a === void 0 ? void 0 : _a.slice(idWithoutCounter.length + 1);
303
+ return counterOfMostRecentlyVisibleEditor === undefined ? undefined : parseInt(counterOfMostRecentlyVisibleEditor);
304
+ }
305
+ getOrCreateCounterForUri(uri) {
306
+ var _a;
307
+ return (_a = this.getCounterForUri(uri)) !== null && _a !== void 0 ? _a : this.createCounterForUri(uri);
308
+ }
309
+ createWidgetOptions(uri, options) {
310
+ var _a;
311
+ const navigatableOptions = super.createWidgetOptions(uri, options);
312
+ navigatableOptions.counter = (_a = options === null || options === void 0 ? void 0 : options.counter) !== null && _a !== void 0 ? _a : this.getOrCreateCounterForUri(uri);
313
+ return navigatableOptions;
314
+ }
315
+ };
316
+ __decorate([
317
+ (0, inversify_1.postConstruct)(),
318
+ __metadata("design:type", Function),
319
+ __metadata("design:paramtypes", []),
320
+ __metadata("design:returntype", void 0)
321
+ ], EditorManager.prototype, "init", null);
322
+ EditorManager = __decorate([
323
+ (0, inversify_1.injectable)()
324
+ ], EditorManager);
325
+ exports.EditorManager = EditorManager;
326
+ /**
327
+ * Provides direct access to the underlying text editor.
328
+ */
329
+ let EditorAccess = class EditorAccess {
330
+ /**
331
+ * The URI of the underlying document from the editor.
332
+ */
333
+ get uri() {
334
+ const editor = this.editor;
335
+ if (editor) {
336
+ return editor.uri.toString();
337
+ }
338
+ return undefined;
339
+ }
340
+ /**
341
+ * The selection location from the text editor.
342
+ */
343
+ get selection() {
344
+ const editor = this.editor;
345
+ if (editor) {
346
+ const uri = editor.uri.toString();
347
+ const range = editor.selection;
348
+ return {
349
+ range,
350
+ uri
351
+ };
352
+ }
353
+ return undefined;
354
+ }
355
+ /**
356
+ * The unique identifier of the language the current editor belongs to.
357
+ */
358
+ get languageId() {
359
+ const editor = this.editor;
360
+ if (editor) {
361
+ return editor.document.languageId;
362
+ }
363
+ return undefined;
364
+ }
365
+ /**
366
+ * The text editor.
367
+ */
368
+ get editor() {
369
+ const editorWidget = this.editorWidget();
370
+ if (editorWidget) {
371
+ return editorWidget.editor;
372
+ }
373
+ return undefined;
374
+ }
375
+ };
376
+ __decorate([
377
+ (0, inversify_1.inject)(EditorManager),
378
+ __metadata("design:type", EditorManager)
379
+ ], EditorAccess.prototype, "editorManager", void 0);
380
+ EditorAccess = __decorate([
381
+ (0, inversify_1.injectable)()
382
+ ], EditorAccess);
383
+ exports.EditorAccess = EditorAccess;
384
+ /**
385
+ * Provides direct access to the currently active text editor.
386
+ */
387
+ let CurrentEditorAccess = class CurrentEditorAccess extends EditorAccess {
388
+ editorWidget() {
389
+ return this.editorManager.currentEditor;
390
+ }
391
+ };
392
+ CurrentEditorAccess = __decorate([
393
+ (0, inversify_1.injectable)()
394
+ ], CurrentEditorAccess);
395
+ exports.CurrentEditorAccess = CurrentEditorAccess;
396
+ /**
397
+ * Provides access to the active text editor.
398
+ */
399
+ let ActiveEditorAccess = class ActiveEditorAccess extends EditorAccess {
400
+ editorWidget() {
401
+ return this.editorManager.activeEditor;
402
+ }
403
+ };
404
+ ActiveEditorAccess = __decorate([
405
+ (0, inversify_1.injectable)()
406
+ ], ActiveEditorAccess);
407
+ exports.ActiveEditorAccess = ActiveEditorAccess;
408
+ (function (EditorAccess) {
409
+ EditorAccess.CURRENT = 'current-editor-access';
410
+ EditorAccess.ACTIVE = 'active-editor-access';
411
+ })(EditorAccess = exports.EditorAccess || (exports.EditorAccess = {}));
412
+ exports.EditorAccess = EditorAccess;
413
413
  //# sourceMappingURL=editor-manager.js.map