@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,282 +1,282 @@
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 NavigationLocationService_1;
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.NavigationLocationService = void 0;
29
- const inversify_1 = require("@theia/core/shared/inversify");
30
- const logger_1 = require("@theia/core/lib/common/logger");
31
- const opener_service_1 = require("@theia/core/lib/browser/opener-service");
32
- const navigation_location_updater_1 = require("./navigation-location-updater");
33
- const navigation_location_similarity_1 = require("./navigation-location-similarity");
34
- const navigation_location_1 = require("./navigation-location");
35
- /**
36
- * The navigation location service.
37
- * It also stores and manages navigation locations and recently closed editors.
38
- */
39
- let NavigationLocationService = NavigationLocationService_1 = class NavigationLocationService {
40
- constructor() {
41
- this.pointer = -1;
42
- this.stack = [];
43
- this.canRegister = true;
44
- this.recentlyClosedEditors = [];
45
- }
46
- /**
47
- * Registers the give locations into the service.
48
- */
49
- register(...locations) {
50
- if (this.canRegister) {
51
- const max = this.maxStackItems();
52
- [...locations].forEach(location => {
53
- if (navigation_location_1.ContentChangeLocation.is(location)) {
54
- this._lastEditLocation = location;
55
- }
56
- const current = this.currentLocation();
57
- this.debug(`Registering new location: ${navigation_location_1.NavigationLocation.toString(location)}.`);
58
- if (!this.isSimilar(current, location)) {
59
- this.debug('Before location registration.');
60
- this.debug(this.stackDump);
61
- // Just like in VSCode; if we are not at the end of stack, we remove anything after.
62
- if (this.stack.length > this.pointer + 1) {
63
- this.debug(`Discarding all locations after ${this.pointer}.`);
64
- this.stack = this.stack.slice(0, this.pointer + 1);
65
- }
66
- this.stack.push(location);
67
- this.pointer = this.stack.length - 1;
68
- if (this.stack.length > max) {
69
- this.debug('Trimming exceeding locations.');
70
- this.stack.shift();
71
- this.pointer--;
72
- }
73
- this.debug('Updating preceding navigation locations.');
74
- for (let i = this.stack.length - 1; i >= 0; i--) {
75
- const candidate = this.stack[i];
76
- const update = this.updater.affects(candidate, location);
77
- if (update === undefined) {
78
- this.debug(`Erasing obsolete location: ${navigation_location_1.NavigationLocation.toString(candidate)}.`);
79
- this.stack.splice(i, 1);
80
- this.pointer--;
81
- }
82
- else if (typeof update !== 'boolean') {
83
- this.debug(`Updating location at index: ${i} => ${navigation_location_1.NavigationLocation.toString(candidate)}.`);
84
- this.stack[i] = update;
85
- }
86
- }
87
- this.debug('After location registration.');
88
- this.debug(this.stackDump);
89
- }
90
- else {
91
- if (current) {
92
- this.debug(`The new location ${navigation_location_1.NavigationLocation.toString(location)} is similar to the current one: ${navigation_location_1.NavigationLocation.toString(current)}. Aborting.`);
93
- }
94
- }
95
- });
96
- }
97
- }
98
- /**
99
- * Navigates one back. Returns with the previous location, or `undefined` if it could not navigate back.
100
- */
101
- async back() {
102
- this.debug('Navigating back.');
103
- if (this.canGoBack()) {
104
- this.pointer--;
105
- await this.reveal();
106
- this.debug(this.stackDump);
107
- return this.currentLocation();
108
- }
109
- this.debug('Cannot navigate back.');
110
- return undefined;
111
- }
112
- /**
113
- * Navigates one forward. Returns with the next location, or `undefined` if it could not go forward.
114
- */
115
- async forward() {
116
- this.debug('Navigating forward.');
117
- if (this.canGoForward()) {
118
- this.pointer++;
119
- await this.reveal();
120
- this.debug(this.stackDump);
121
- return this.currentLocation();
122
- }
123
- this.debug('Cannot navigate forward.');
124
- return undefined;
125
- }
126
- /**
127
- * Checks whether the service can go [`back`](#back).
128
- */
129
- canGoBack() {
130
- return this.pointer >= 1;
131
- }
132
- /**
133
- * Checks whether the service can go [`forward`](#forward).
134
- */
135
- canGoForward() {
136
- return this.pointer >= 0 && this.pointer !== this.stack.length - 1;
137
- }
138
- /**
139
- * Returns with all known navigation locations in chronological order.
140
- */
141
- locations() {
142
- return this.stack;
143
- }
144
- /**
145
- * Returns with the current location.
146
- */
147
- currentLocation() {
148
- return this.stack[this.pointer];
149
- }
150
- /**
151
- * Returns with the location of the most recent edition if any. If there were no modifications,
152
- * returns `undefined`.
153
- */
154
- lastEditLocation() {
155
- return this._lastEditLocation;
156
- }
157
- /**
158
- * Clears the total history.
159
- */
160
- clearHistory() {
161
- this.stack = [];
162
- this.pointer = -1;
163
- this._lastEditLocation = undefined;
164
- this.recentlyClosedEditors = [];
165
- }
166
- /**
167
- * Reveals the location argument. If not given, reveals the `current location`. Does nothing, if the argument is `undefined`.
168
- */
169
- async reveal(location = this.currentLocation()) {
170
- if (location === undefined) {
171
- return;
172
- }
173
- try {
174
- this.canRegister = false;
175
- const { uri } = location;
176
- const options = this.toOpenerOptions(location);
177
- await (0, opener_service_1.open)(this.openerService, uri, options);
178
- }
179
- catch (e) {
180
- this.logger.error(`Error occurred while revealing location: ${navigation_location_1.NavigationLocation.toString(location)}.`, e);
181
- }
182
- finally {
183
- this.canRegister = true;
184
- }
185
- }
186
- /**
187
- * `true` if the two locations are similar.
188
- */
189
- isSimilar(left, right) {
190
- return this.similarity.similar(left, right);
191
- }
192
- /**
193
- * Returns with the number of navigation locations that the application can handle and manage.
194
- * When the number of locations exceeds this number, old locations will be erased.
195
- */
196
- maxStackItems() {
197
- return NavigationLocationService_1.MAX_STACK_ITEMS;
198
- }
199
- /**
200
- * Returns with the opener option for the location argument.
201
- */
202
- toOpenerOptions(location) {
203
- let { start } = navigation_location_1.NavigationLocation.range(location);
204
- // Here, the `start` and represents the previous state that has been updated with the `text`.
205
- // So we calculate the range by appending the `text` length to the `start`.
206
- if (navigation_location_1.ContentChangeLocation.is(location)) {
207
- start = { ...start, character: start.character + location.context.text.length };
208
- }
209
- return {
210
- selection: navigation_location_1.Range.create(start, start)
211
- };
212
- }
213
- async debug(message) {
214
- this.logger.trace(typeof message === 'string' ? message : message());
215
- }
216
- get stackDump() {
217
- return `----- Navigation location stack [${new Date()}] -----
218
- Pointer: ${this.pointer}
219
- ${this.stack.map((location, i) => `${i}: ${JSON.stringify(navigation_location_1.NavigationLocation.toObject(location))}`).join('\n')}
220
- ----- o -----`;
221
- }
222
- /**
223
- * Get the recently closed editors stack in chronological order.
224
- *
225
- * @returns readonly closed editors stack.
226
- */
227
- get closedEditorsStack() {
228
- return this.recentlyClosedEditors;
229
- }
230
- /**
231
- * Get the last recently closed editor.
232
- *
233
- * @returns the recently closed editor if it exists.
234
- */
235
- getLastClosedEditor() {
236
- return this.recentlyClosedEditors[this.recentlyClosedEditors.length - 1];
237
- }
238
- /**
239
- * Add the recently closed editor to the history.
240
- *
241
- * @param editor the recently closed editor.
242
- */
243
- addClosedEditor(editor) {
244
- this.removeClosedEditor(editor.uri);
245
- this.recentlyClosedEditors.push(editor);
246
- // Removes the oldest entry from the history if the maximum size is reached.
247
- if (this.recentlyClosedEditors.length > NavigationLocationService_1.MAX_RECENTLY_CLOSED_EDITORS) {
248
- this.recentlyClosedEditors.shift();
249
- }
250
- }
251
- /**
252
- * Remove all occurrences of the given editor in the history if they exist.
253
- *
254
- * @param uri the uri of the editor that should be removed from the history.
255
- */
256
- removeClosedEditor(uri) {
257
- this.recentlyClosedEditors = this.recentlyClosedEditors.filter(e => !uri.isEqual(e.uri));
258
- }
259
- };
260
- NavigationLocationService.MAX_STACK_ITEMS = 30;
261
- NavigationLocationService.MAX_RECENTLY_CLOSED_EDITORS = 20;
262
- __decorate([
263
- (0, inversify_1.inject)(logger_1.ILogger),
264
- __metadata("design:type", Object)
265
- ], NavigationLocationService.prototype, "logger", void 0);
266
- __decorate([
267
- (0, inversify_1.inject)(opener_service_1.OpenerService),
268
- __metadata("design:type", Object)
269
- ], NavigationLocationService.prototype, "openerService", void 0);
270
- __decorate([
271
- (0, inversify_1.inject)(navigation_location_updater_1.NavigationLocationUpdater),
272
- __metadata("design:type", navigation_location_updater_1.NavigationLocationUpdater)
273
- ], NavigationLocationService.prototype, "updater", void 0);
274
- __decorate([
275
- (0, inversify_1.inject)(navigation_location_similarity_1.NavigationLocationSimilarity),
276
- __metadata("design:type", navigation_location_similarity_1.NavigationLocationSimilarity)
277
- ], NavigationLocationService.prototype, "similarity", void 0);
278
- NavigationLocationService = NavigationLocationService_1 = __decorate([
279
- (0, inversify_1.injectable)()
280
- ], NavigationLocationService);
281
- exports.NavigationLocationService = NavigationLocationService;
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 NavigationLocationService_1;
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.NavigationLocationService = void 0;
29
+ const inversify_1 = require("@theia/core/shared/inversify");
30
+ const logger_1 = require("@theia/core/lib/common/logger");
31
+ const opener_service_1 = require("@theia/core/lib/browser/opener-service");
32
+ const navigation_location_updater_1 = require("./navigation-location-updater");
33
+ const navigation_location_similarity_1 = require("./navigation-location-similarity");
34
+ const navigation_location_1 = require("./navigation-location");
35
+ /**
36
+ * The navigation location service.
37
+ * It also stores and manages navigation locations and recently closed editors.
38
+ */
39
+ let NavigationLocationService = NavigationLocationService_1 = class NavigationLocationService {
40
+ constructor() {
41
+ this.pointer = -1;
42
+ this.stack = [];
43
+ this.canRegister = true;
44
+ this.recentlyClosedEditors = [];
45
+ }
46
+ /**
47
+ * Registers the give locations into the service.
48
+ */
49
+ register(...locations) {
50
+ if (this.canRegister) {
51
+ const max = this.maxStackItems();
52
+ [...locations].forEach(location => {
53
+ if (navigation_location_1.ContentChangeLocation.is(location)) {
54
+ this._lastEditLocation = location;
55
+ }
56
+ const current = this.currentLocation();
57
+ this.debug(`Registering new location: ${navigation_location_1.NavigationLocation.toString(location)}.`);
58
+ if (!this.isSimilar(current, location)) {
59
+ this.debug('Before location registration.');
60
+ this.debug(this.stackDump);
61
+ // Just like in VSCode; if we are not at the end of stack, we remove anything after.
62
+ if (this.stack.length > this.pointer + 1) {
63
+ this.debug(`Discarding all locations after ${this.pointer}.`);
64
+ this.stack = this.stack.slice(0, this.pointer + 1);
65
+ }
66
+ this.stack.push(location);
67
+ this.pointer = this.stack.length - 1;
68
+ if (this.stack.length > max) {
69
+ this.debug('Trimming exceeding locations.');
70
+ this.stack.shift();
71
+ this.pointer--;
72
+ }
73
+ this.debug('Updating preceding navigation locations.');
74
+ for (let i = this.stack.length - 1; i >= 0; i--) {
75
+ const candidate = this.stack[i];
76
+ const update = this.updater.affects(candidate, location);
77
+ if (update === undefined) {
78
+ this.debug(`Erasing obsolete location: ${navigation_location_1.NavigationLocation.toString(candidate)}.`);
79
+ this.stack.splice(i, 1);
80
+ this.pointer--;
81
+ }
82
+ else if (typeof update !== 'boolean') {
83
+ this.debug(`Updating location at index: ${i} => ${navigation_location_1.NavigationLocation.toString(candidate)}.`);
84
+ this.stack[i] = update;
85
+ }
86
+ }
87
+ this.debug('After location registration.');
88
+ this.debug(this.stackDump);
89
+ }
90
+ else {
91
+ if (current) {
92
+ this.debug(`The new location ${navigation_location_1.NavigationLocation.toString(location)} is similar to the current one: ${navigation_location_1.NavigationLocation.toString(current)}. Aborting.`);
93
+ }
94
+ }
95
+ });
96
+ }
97
+ }
98
+ /**
99
+ * Navigates one back. Returns with the previous location, or `undefined` if it could not navigate back.
100
+ */
101
+ async back() {
102
+ this.debug('Navigating back.');
103
+ if (this.canGoBack()) {
104
+ this.pointer--;
105
+ await this.reveal();
106
+ this.debug(this.stackDump);
107
+ return this.currentLocation();
108
+ }
109
+ this.debug('Cannot navigate back.');
110
+ return undefined;
111
+ }
112
+ /**
113
+ * Navigates one forward. Returns with the next location, or `undefined` if it could not go forward.
114
+ */
115
+ async forward() {
116
+ this.debug('Navigating forward.');
117
+ if (this.canGoForward()) {
118
+ this.pointer++;
119
+ await this.reveal();
120
+ this.debug(this.stackDump);
121
+ return this.currentLocation();
122
+ }
123
+ this.debug('Cannot navigate forward.');
124
+ return undefined;
125
+ }
126
+ /**
127
+ * Checks whether the service can go [`back`](#back).
128
+ */
129
+ canGoBack() {
130
+ return this.pointer >= 1;
131
+ }
132
+ /**
133
+ * Checks whether the service can go [`forward`](#forward).
134
+ */
135
+ canGoForward() {
136
+ return this.pointer >= 0 && this.pointer !== this.stack.length - 1;
137
+ }
138
+ /**
139
+ * Returns with all known navigation locations in chronological order.
140
+ */
141
+ locations() {
142
+ return this.stack;
143
+ }
144
+ /**
145
+ * Returns with the current location.
146
+ */
147
+ currentLocation() {
148
+ return this.stack[this.pointer];
149
+ }
150
+ /**
151
+ * Returns with the location of the most recent edition if any. If there were no modifications,
152
+ * returns `undefined`.
153
+ */
154
+ lastEditLocation() {
155
+ return this._lastEditLocation;
156
+ }
157
+ /**
158
+ * Clears the total history.
159
+ */
160
+ clearHistory() {
161
+ this.stack = [];
162
+ this.pointer = -1;
163
+ this._lastEditLocation = undefined;
164
+ this.recentlyClosedEditors = [];
165
+ }
166
+ /**
167
+ * Reveals the location argument. If not given, reveals the `current location`. Does nothing, if the argument is `undefined`.
168
+ */
169
+ async reveal(location = this.currentLocation()) {
170
+ if (location === undefined) {
171
+ return;
172
+ }
173
+ try {
174
+ this.canRegister = false;
175
+ const { uri } = location;
176
+ const options = this.toOpenerOptions(location);
177
+ await (0, opener_service_1.open)(this.openerService, uri, options);
178
+ }
179
+ catch (e) {
180
+ this.logger.error(`Error occurred while revealing location: ${navigation_location_1.NavigationLocation.toString(location)}.`, e);
181
+ }
182
+ finally {
183
+ this.canRegister = true;
184
+ }
185
+ }
186
+ /**
187
+ * `true` if the two locations are similar.
188
+ */
189
+ isSimilar(left, right) {
190
+ return this.similarity.similar(left, right);
191
+ }
192
+ /**
193
+ * Returns with the number of navigation locations that the application can handle and manage.
194
+ * When the number of locations exceeds this number, old locations will be erased.
195
+ */
196
+ maxStackItems() {
197
+ return NavigationLocationService_1.MAX_STACK_ITEMS;
198
+ }
199
+ /**
200
+ * Returns with the opener option for the location argument.
201
+ */
202
+ toOpenerOptions(location) {
203
+ let { start } = navigation_location_1.NavigationLocation.range(location);
204
+ // Here, the `start` and represents the previous state that has been updated with the `text`.
205
+ // So we calculate the range by appending the `text` length to the `start`.
206
+ if (navigation_location_1.ContentChangeLocation.is(location)) {
207
+ start = { ...start, character: start.character + location.context.text.length };
208
+ }
209
+ return {
210
+ selection: navigation_location_1.Range.create(start, start)
211
+ };
212
+ }
213
+ async debug(message) {
214
+ this.logger.trace(typeof message === 'string' ? message : message());
215
+ }
216
+ get stackDump() {
217
+ return `----- Navigation location stack [${new Date()}] -----
218
+ Pointer: ${this.pointer}
219
+ ${this.stack.map((location, i) => `${i}: ${JSON.stringify(navigation_location_1.NavigationLocation.toObject(location))}`).join('\n')}
220
+ ----- o -----`;
221
+ }
222
+ /**
223
+ * Get the recently closed editors stack in chronological order.
224
+ *
225
+ * @returns readonly closed editors stack.
226
+ */
227
+ get closedEditorsStack() {
228
+ return this.recentlyClosedEditors;
229
+ }
230
+ /**
231
+ * Get the last recently closed editor.
232
+ *
233
+ * @returns the recently closed editor if it exists.
234
+ */
235
+ getLastClosedEditor() {
236
+ return this.recentlyClosedEditors[this.recentlyClosedEditors.length - 1];
237
+ }
238
+ /**
239
+ * Add the recently closed editor to the history.
240
+ *
241
+ * @param editor the recently closed editor.
242
+ */
243
+ addClosedEditor(editor) {
244
+ this.removeClosedEditor(editor.uri);
245
+ this.recentlyClosedEditors.push(editor);
246
+ // Removes the oldest entry from the history if the maximum size is reached.
247
+ if (this.recentlyClosedEditors.length > NavigationLocationService_1.MAX_RECENTLY_CLOSED_EDITORS) {
248
+ this.recentlyClosedEditors.shift();
249
+ }
250
+ }
251
+ /**
252
+ * Remove all occurrences of the given editor in the history if they exist.
253
+ *
254
+ * @param uri the uri of the editor that should be removed from the history.
255
+ */
256
+ removeClosedEditor(uri) {
257
+ this.recentlyClosedEditors = this.recentlyClosedEditors.filter(e => !uri.isEqual(e.uri));
258
+ }
259
+ };
260
+ NavigationLocationService.MAX_STACK_ITEMS = 30;
261
+ NavigationLocationService.MAX_RECENTLY_CLOSED_EDITORS = 20;
262
+ __decorate([
263
+ (0, inversify_1.inject)(logger_1.ILogger),
264
+ __metadata("design:type", Object)
265
+ ], NavigationLocationService.prototype, "logger", void 0);
266
+ __decorate([
267
+ (0, inversify_1.inject)(opener_service_1.OpenerService),
268
+ __metadata("design:type", Object)
269
+ ], NavigationLocationService.prototype, "openerService", void 0);
270
+ __decorate([
271
+ (0, inversify_1.inject)(navigation_location_updater_1.NavigationLocationUpdater),
272
+ __metadata("design:type", navigation_location_updater_1.NavigationLocationUpdater)
273
+ ], NavigationLocationService.prototype, "updater", void 0);
274
+ __decorate([
275
+ (0, inversify_1.inject)(navigation_location_similarity_1.NavigationLocationSimilarity),
276
+ __metadata("design:type", navigation_location_similarity_1.NavigationLocationSimilarity)
277
+ ], NavigationLocationService.prototype, "similarity", void 0);
278
+ NavigationLocationService = NavigationLocationService_1 = __decorate([
279
+ (0, inversify_1.injectable)()
280
+ ], NavigationLocationService);
281
+ exports.NavigationLocationService = NavigationLocationService;
282
282
  //# sourceMappingURL=navigation-location-service.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=navigation-location-service.spec.d.ts.map