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