@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,344 +1,344 @@
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 EditorNavigationContribution_1;
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.EditorNavigationContribution = void 0;
29
- const inversify_1 = require("@theia/core/shared/inversify");
30
- const logger_1 = require("@theia/core/lib/common/logger");
31
- const storage_service_1 = require("@theia/core/lib/browser/storage-service");
32
- const disposable_1 = require("@theia/core/lib/common/disposable");
33
- const command_1 = require("@theia/core/lib/common/command");
34
- const editor_command_1 = require("./editor-command");
35
- const editor_manager_1 = require("./editor-manager");
36
- const navigation_location_1 = require("./navigation/navigation-location");
37
- const navigation_location_service_1 = require("./navigation/navigation-location-service");
38
- const browser_1 = require("@theia/core/lib/browser");
39
- const dialogs_1 = require("@theia/core/lib/browser/dialogs");
40
- const core_1 = require("@theia/core");
41
- let EditorNavigationContribution = EditorNavigationContribution_1 = class EditorNavigationContribution {
42
- constructor() {
43
- this.toDispose = new disposable_1.DisposableCollection();
44
- this.toDisposePerCurrentEditor = new disposable_1.DisposableCollection();
45
- }
46
- init() {
47
- this.toDispose.pushAll([
48
- // TODO listen on file resource changes, if a file gets deleted, remove the corresponding navigation locations (if any).
49
- // This would require introducing the FS dependency in the editor extension.
50
- this.editorManager.onCurrentEditorChanged(this.onCurrentEditorChanged.bind(this)),
51
- this.editorManager.onCreated(widget => {
52
- this.locationStack.removeClosedEditor(widget.editor.uri);
53
- widget.disposed.connect(() => this.locationStack.addClosedEditor({
54
- uri: widget.editor.uri,
55
- viewState: widget.editor.storeViewState()
56
- }));
57
- })
58
- ]);
59
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.GO_BACK.id, {
60
- execute: () => this.locationStack.back(),
61
- isEnabled: () => this.locationStack.canGoBack()
62
- });
63
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.GO_FORWARD.id, {
64
- execute: () => this.locationStack.forward(),
65
- isEnabled: () => this.locationStack.canGoForward()
66
- });
67
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.GO_LAST_EDIT.id, {
68
- execute: () => this.locationStack.reveal(this.locationStack.lastEditLocation()),
69
- isEnabled: () => !!this.locationStack.lastEditLocation()
70
- });
71
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.CLEAR_EDITOR_HISTORY.id, {
72
- execute: async () => {
73
- const shouldClear = await new dialogs_1.ConfirmDialog({
74
- title: core_1.nls.localizeByDefault('Clear Editor History'),
75
- msg: core_1.nls.localizeByDefault('Do you want to clear the history of recently opened editors?'),
76
- ok: dialogs_1.Dialog.YES,
77
- cancel: dialogs_1.Dialog.NO
78
- }).open();
79
- if (shouldClear) {
80
- this.locationStack.clearHistory();
81
- }
82
- },
83
- isEnabled: () => this.locationStack.locations().length > 0
84
- });
85
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.TOGGLE_MINIMAP.id, {
86
- execute: () => this.toggleMinimap(),
87
- isEnabled: () => true,
88
- isToggled: () => this.isMinimapEnabled()
89
- });
90
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.TOGGLE_RENDER_WHITESPACE.id, {
91
- execute: () => this.toggleRenderWhitespace(),
92
- isEnabled: () => true,
93
- isToggled: () => this.isRenderWhitespaceEnabled()
94
- });
95
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.TOGGLE_WORD_WRAP.id, {
96
- execute: () => this.toggleWordWrap(),
97
- isEnabled: () => true,
98
- });
99
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.TOGGLE_STICKY_SCROLL.id, {
100
- execute: () => this.toggleStickyScroll(),
101
- isEnabled: () => true,
102
- isToggled: () => this.isStickyScrollEnabled()
103
- });
104
- this.commandRegistry.registerHandler(editor_command_1.EditorCommands.REOPEN_CLOSED_EDITOR.id, {
105
- execute: () => this.reopenLastClosedEditor()
106
- });
107
- this.installMouseNavigationSupport();
108
- }
109
- async installMouseNavigationSupport() {
110
- const mouseNavigationSupport = new disposable_1.DisposableCollection();
111
- const updateMouseNavigationListener = () => {
112
- mouseNavigationSupport.dispose();
113
- if (this.shouldNavigateWithMouse()) {
114
- mouseNavigationSupport.push((0, browser_1.addEventListener)(document.body, 'mousedown', event => this.onMouseDown(event), true));
115
- }
116
- };
117
- this.toDispose.push(this.preferenceService.onPreferenceChanged(change => {
118
- if (change.preferenceName === EditorNavigationContribution_1.MOUSE_NAVIGATION_PREFERENCE) {
119
- updateMouseNavigationListener();
120
- }
121
- }));
122
- updateMouseNavigationListener();
123
- this.toDispose.push(mouseNavigationSupport);
124
- }
125
- async onMouseDown(event) {
126
- // Support navigation in history when mouse buttons 4/5 are pressed
127
- switch (event.button) {
128
- case 3:
129
- event.preventDefault();
130
- this.locationStack.back();
131
- break;
132
- case 4:
133
- event.preventDefault();
134
- this.locationStack.forward();
135
- break;
136
- }
137
- }
138
- /**
139
- * Reopens the last closed editor with its stored view state if possible from history.
140
- * If the editor cannot be restored, continue to the next editor in history.
141
- */
142
- async reopenLastClosedEditor() {
143
- const lastClosedEditor = this.locationStack.getLastClosedEditor();
144
- if (lastClosedEditor === undefined) {
145
- return;
146
- }
147
- try {
148
- const widget = await this.editorManager.open(lastClosedEditor.uri);
149
- widget.editor.restoreViewState(lastClosedEditor.viewState);
150
- }
151
- catch {
152
- this.locationStack.removeClosedEditor(lastClosedEditor.uri);
153
- this.reopenLastClosedEditor();
154
- }
155
- }
156
- async onStart() {
157
- this.restoreState();
158
- }
159
- onStop() {
160
- this.storeState();
161
- this.dispose();
162
- }
163
- dispose() {
164
- this.toDispose.dispose();
165
- }
166
- /**
167
- * Toggle the editor word wrap behavior.
168
- */
169
- async toggleWordWrap() {
170
- // Get the current word wrap.
171
- const wordWrap = this.preferenceService.get('editor.wordWrap');
172
- if (wordWrap === undefined) {
173
- return;
174
- }
175
- // The list of allowed word wrap values.
176
- const values = ['off', 'on', 'wordWrapColumn', 'bounded'];
177
- // Get the index of the current value, and toggle to the next available value.
178
- const index = values.indexOf(wordWrap) + 1;
179
- if (index > -1) {
180
- this.preferenceService.set('editor.wordWrap', values[index % values.length], browser_1.PreferenceScope.User);
181
- }
182
- }
183
- /**
184
- * Toggle the display of sticky scroll in the editor.
185
- */
186
- async toggleStickyScroll() {
187
- const value = this.preferenceService.get('editor.stickyScroll.enabled');
188
- this.preferenceService.set('editor.stickyScroll.enabled', !value, browser_1.PreferenceScope.User);
189
- }
190
- /**
191
- * Toggle the display of minimap in the editor.
192
- */
193
- async toggleMinimap() {
194
- const value = this.preferenceService.get('editor.minimap.enabled');
195
- this.preferenceService.set('editor.minimap.enabled', !value, browser_1.PreferenceScope.User);
196
- }
197
- /**
198
- * Toggle the rendering of whitespace in the editor.
199
- */
200
- async toggleRenderWhitespace() {
201
- const renderWhitespace = this.preferenceService.get('editor.renderWhitespace');
202
- let updatedRenderWhitespace;
203
- if (renderWhitespace === 'none') {
204
- updatedRenderWhitespace = 'all';
205
- }
206
- else {
207
- updatedRenderWhitespace = 'none';
208
- }
209
- this.preferenceService.set('editor.renderWhitespace', updatedRenderWhitespace, browser_1.PreferenceScope.User);
210
- }
211
- onCurrentEditorChanged(editorWidget) {
212
- this.toDisposePerCurrentEditor.dispose();
213
- if (editorWidget) {
214
- const { editor } = editorWidget;
215
- this.toDisposePerCurrentEditor.pushAll([
216
- // Instead of registering an `onCursorPositionChanged` listener, we treat the zero length selection as a cursor position change.
217
- // Otherwise we would have two events for a single cursor change interaction.
218
- editor.onSelectionChanged(selection => this.onSelectionChanged(editor, selection)),
219
- editor.onDocumentContentChanged(event => this.onDocumentContentChanged(editor, event))
220
- ]);
221
- this.locationStack.register(navigation_location_1.NavigationLocation.create(editor, editor.selection));
222
- }
223
- }
224
- onCursorPositionChanged(editor, position) {
225
- this.locationStack.register(navigation_location_1.NavigationLocation.create(editor, position));
226
- }
227
- onSelectionChanged(editor, selection) {
228
- if (this.isZeroLengthRange(selection)) {
229
- this.onCursorPositionChanged(editor, selection.start);
230
- }
231
- else {
232
- this.locationStack.register(navigation_location_1.NavigationLocation.create(editor, selection));
233
- }
234
- }
235
- onDocumentContentChanged(editor, event) {
236
- if (event.contentChanges.length > 0) {
237
- this.locationStack.register(navigation_location_1.NavigationLocation.create(editor, event.contentChanges[0]));
238
- }
239
- }
240
- /**
241
- * `true` if the `range` argument has zero length. In other words, the `start` and the `end` positions are the same. Otherwise, `false`.
242
- */
243
- isZeroLengthRange(range) {
244
- const { start, end } = range;
245
- return start.line === end.line && start.character === end.character;
246
- }
247
- async storeState() {
248
- this.storageService.setData(EditorNavigationContribution_1.ID, {
249
- locations: this.locationStack.locations().map(navigation_location_1.NavigationLocation.toObject)
250
- });
251
- this.storageService.setData(EditorNavigationContribution_1.CLOSED_EDITORS_KEY, {
252
- closedEditors: this.shouldStoreClosedEditors() ? this.locationStack.closedEditorsStack.map(navigation_location_1.RecentlyClosedEditor.toObject) : []
253
- });
254
- }
255
- async restoreState() {
256
- await this.restoreNavigationLocations();
257
- await this.restoreClosedEditors();
258
- }
259
- async restoreNavigationLocations() {
260
- const raw = await this.storageService.getData(EditorNavigationContribution_1.ID);
261
- if (raw && raw.locations) {
262
- const locations = [];
263
- for (let i = 0; i < raw.locations.length; i++) {
264
- const location = navigation_location_1.NavigationLocation.fromObject(raw.locations[i]);
265
- if (location) {
266
- locations.push(location);
267
- }
268
- else {
269
- this.logger.warn('Could not restore the state of the editor navigation history.');
270
- return;
271
- }
272
- }
273
- this.locationStack.register(...locations);
274
- }
275
- }
276
- async restoreClosedEditors() {
277
- const raw = await this.storageService.getData(EditorNavigationContribution_1.CLOSED_EDITORS_KEY);
278
- if (raw && raw.closedEditors) {
279
- for (let i = 0; i < raw.closedEditors.length; i++) {
280
- const editor = navigation_location_1.RecentlyClosedEditor.fromObject(raw.closedEditors[i]);
281
- if (editor) {
282
- this.locationStack.addClosedEditor(editor);
283
- }
284
- else {
285
- this.logger.warn('Could not restore the state of the closed editors stack.');
286
- }
287
- }
288
- }
289
- }
290
- isMinimapEnabled() {
291
- return !!this.preferenceService.get('editor.minimap.enabled');
292
- }
293
- isRenderWhitespaceEnabled() {
294
- const renderWhitespace = this.preferenceService.get('editor.renderWhitespace');
295
- return renderWhitespace === 'none' ? false : true;
296
- }
297
- shouldStoreClosedEditors() {
298
- return !!this.preferenceService.get('editor.history.persistClosedEditors');
299
- }
300
- shouldNavigateWithMouse() {
301
- return !!this.preferenceService.get(EditorNavigationContribution_1.MOUSE_NAVIGATION_PREFERENCE);
302
- }
303
- isStickyScrollEnabled() {
304
- return !!this.preferenceService.get('editor.stickyScroll.enabled');
305
- }
306
- };
307
- EditorNavigationContribution.ID = 'editor-navigation-contribution';
308
- EditorNavigationContribution.CLOSED_EDITORS_KEY = 'recently-closed-editors';
309
- EditorNavigationContribution.MOUSE_NAVIGATION_PREFERENCE = 'workbench.editor.mouseBackForwardToNavigate';
310
- __decorate([
311
- (0, inversify_1.inject)(logger_1.ILogger),
312
- __metadata("design:type", Object)
313
- ], EditorNavigationContribution.prototype, "logger", void 0);
314
- __decorate([
315
- (0, inversify_1.inject)(editor_manager_1.EditorManager),
316
- __metadata("design:type", editor_manager_1.EditorManager)
317
- ], EditorNavigationContribution.prototype, "editorManager", void 0);
318
- __decorate([
319
- (0, inversify_1.inject)(navigation_location_service_1.NavigationLocationService),
320
- __metadata("design:type", navigation_location_service_1.NavigationLocationService)
321
- ], EditorNavigationContribution.prototype, "locationStack", void 0);
322
- __decorate([
323
- (0, inversify_1.inject)(storage_service_1.StorageService),
324
- __metadata("design:type", Object)
325
- ], EditorNavigationContribution.prototype, "storageService", void 0);
326
- __decorate([
327
- (0, inversify_1.inject)(browser_1.PreferenceService),
328
- __metadata("design:type", Object)
329
- ], EditorNavigationContribution.prototype, "preferenceService", void 0);
330
- __decorate([
331
- (0, inversify_1.inject)(command_1.CommandRegistry),
332
- __metadata("design:type", command_1.CommandRegistry)
333
- ], EditorNavigationContribution.prototype, "commandRegistry", void 0);
334
- __decorate([
335
- (0, inversify_1.postConstruct)(),
336
- __metadata("design:type", Function),
337
- __metadata("design:paramtypes", []),
338
- __metadata("design:returntype", void 0)
339
- ], EditorNavigationContribution.prototype, "init", null);
340
- EditorNavigationContribution = EditorNavigationContribution_1 = __decorate([
341
- (0, inversify_1.injectable)()
342
- ], EditorNavigationContribution);
343
- exports.EditorNavigationContribution = EditorNavigationContribution;
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 EditorNavigationContribution_1;
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.EditorNavigationContribution = void 0;
29
+ const inversify_1 = require("@theia/core/shared/inversify");
30
+ const logger_1 = require("@theia/core/lib/common/logger");
31
+ const storage_service_1 = require("@theia/core/lib/browser/storage-service");
32
+ const disposable_1 = require("@theia/core/lib/common/disposable");
33
+ const command_1 = require("@theia/core/lib/common/command");
34
+ const editor_command_1 = require("./editor-command");
35
+ const editor_manager_1 = require("./editor-manager");
36
+ const navigation_location_1 = require("./navigation/navigation-location");
37
+ const navigation_location_service_1 = require("./navigation/navigation-location-service");
38
+ const browser_1 = require("@theia/core/lib/browser");
39
+ const dialogs_1 = require("@theia/core/lib/browser/dialogs");
40
+ const core_1 = require("@theia/core");
41
+ let EditorNavigationContribution = EditorNavigationContribution_1 = class EditorNavigationContribution {
42
+ constructor() {
43
+ this.toDispose = new disposable_1.DisposableCollection();
44
+ this.toDisposePerCurrentEditor = new disposable_1.DisposableCollection();
45
+ }
46
+ init() {
47
+ this.toDispose.pushAll([
48
+ // TODO listen on file resource changes, if a file gets deleted, remove the corresponding navigation locations (if any).
49
+ // This would require introducing the FS dependency in the editor extension.
50
+ this.editorManager.onCurrentEditorChanged(this.onCurrentEditorChanged.bind(this)),
51
+ this.editorManager.onCreated(widget => {
52
+ this.locationStack.removeClosedEditor(widget.editor.uri);
53
+ widget.disposed.connect(() => this.locationStack.addClosedEditor({
54
+ uri: widget.editor.uri,
55
+ viewState: widget.editor.storeViewState()
56
+ }));
57
+ })
58
+ ]);
59
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.GO_BACK.id, {
60
+ execute: () => this.locationStack.back(),
61
+ isEnabled: () => this.locationStack.canGoBack()
62
+ });
63
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.GO_FORWARD.id, {
64
+ execute: () => this.locationStack.forward(),
65
+ isEnabled: () => this.locationStack.canGoForward()
66
+ });
67
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.GO_LAST_EDIT.id, {
68
+ execute: () => this.locationStack.reveal(this.locationStack.lastEditLocation()),
69
+ isEnabled: () => !!this.locationStack.lastEditLocation()
70
+ });
71
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.CLEAR_EDITOR_HISTORY.id, {
72
+ execute: async () => {
73
+ const shouldClear = await new dialogs_1.ConfirmDialog({
74
+ title: core_1.nls.localizeByDefault('Clear Editor History'),
75
+ msg: core_1.nls.localizeByDefault('Do you want to clear the history of recently opened editors?'),
76
+ ok: dialogs_1.Dialog.YES,
77
+ cancel: dialogs_1.Dialog.NO
78
+ }).open();
79
+ if (shouldClear) {
80
+ this.locationStack.clearHistory();
81
+ }
82
+ },
83
+ isEnabled: () => this.locationStack.locations().length > 0
84
+ });
85
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.TOGGLE_MINIMAP.id, {
86
+ execute: () => this.toggleMinimap(),
87
+ isEnabled: () => true,
88
+ isToggled: () => this.isMinimapEnabled()
89
+ });
90
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.TOGGLE_RENDER_WHITESPACE.id, {
91
+ execute: () => this.toggleRenderWhitespace(),
92
+ isEnabled: () => true,
93
+ isToggled: () => this.isRenderWhitespaceEnabled()
94
+ });
95
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.TOGGLE_WORD_WRAP.id, {
96
+ execute: () => this.toggleWordWrap(),
97
+ isEnabled: () => true,
98
+ });
99
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.TOGGLE_STICKY_SCROLL.id, {
100
+ execute: () => this.toggleStickyScroll(),
101
+ isEnabled: () => true,
102
+ isToggled: () => this.isStickyScrollEnabled()
103
+ });
104
+ this.commandRegistry.registerHandler(editor_command_1.EditorCommands.REOPEN_CLOSED_EDITOR.id, {
105
+ execute: () => this.reopenLastClosedEditor()
106
+ });
107
+ this.installMouseNavigationSupport();
108
+ }
109
+ async installMouseNavigationSupport() {
110
+ const mouseNavigationSupport = new disposable_1.DisposableCollection();
111
+ const updateMouseNavigationListener = () => {
112
+ mouseNavigationSupport.dispose();
113
+ if (this.shouldNavigateWithMouse()) {
114
+ mouseNavigationSupport.push((0, browser_1.addEventListener)(document.body, 'mousedown', event => this.onMouseDown(event), true));
115
+ }
116
+ };
117
+ this.toDispose.push(this.preferenceService.onPreferenceChanged(change => {
118
+ if (change.preferenceName === EditorNavigationContribution_1.MOUSE_NAVIGATION_PREFERENCE) {
119
+ updateMouseNavigationListener();
120
+ }
121
+ }));
122
+ updateMouseNavigationListener();
123
+ this.toDispose.push(mouseNavigationSupport);
124
+ }
125
+ async onMouseDown(event) {
126
+ // Support navigation in history when mouse buttons 4/5 are pressed
127
+ switch (event.button) {
128
+ case 3:
129
+ event.preventDefault();
130
+ this.locationStack.back();
131
+ break;
132
+ case 4:
133
+ event.preventDefault();
134
+ this.locationStack.forward();
135
+ break;
136
+ }
137
+ }
138
+ /**
139
+ * Reopens the last closed editor with its stored view state if possible from history.
140
+ * If the editor cannot be restored, continue to the next editor in history.
141
+ */
142
+ async reopenLastClosedEditor() {
143
+ const lastClosedEditor = this.locationStack.getLastClosedEditor();
144
+ if (lastClosedEditor === undefined) {
145
+ return;
146
+ }
147
+ try {
148
+ const widget = await this.editorManager.open(lastClosedEditor.uri);
149
+ widget.editor.restoreViewState(lastClosedEditor.viewState);
150
+ }
151
+ catch {
152
+ this.locationStack.removeClosedEditor(lastClosedEditor.uri);
153
+ this.reopenLastClosedEditor();
154
+ }
155
+ }
156
+ async onStart() {
157
+ this.restoreState();
158
+ }
159
+ onStop() {
160
+ this.storeState();
161
+ this.dispose();
162
+ }
163
+ dispose() {
164
+ this.toDispose.dispose();
165
+ }
166
+ /**
167
+ * Toggle the editor word wrap behavior.
168
+ */
169
+ async toggleWordWrap() {
170
+ // Get the current word wrap.
171
+ const wordWrap = this.preferenceService.get('editor.wordWrap');
172
+ if (wordWrap === undefined) {
173
+ return;
174
+ }
175
+ // The list of allowed word wrap values.
176
+ const values = ['off', 'on', 'wordWrapColumn', 'bounded'];
177
+ // Get the index of the current value, and toggle to the next available value.
178
+ const index = values.indexOf(wordWrap) + 1;
179
+ if (index > -1) {
180
+ this.preferenceService.set('editor.wordWrap', values[index % values.length], browser_1.PreferenceScope.User);
181
+ }
182
+ }
183
+ /**
184
+ * Toggle the display of sticky scroll in the editor.
185
+ */
186
+ async toggleStickyScroll() {
187
+ const value = this.preferenceService.get('editor.stickyScroll.enabled');
188
+ this.preferenceService.set('editor.stickyScroll.enabled', !value, browser_1.PreferenceScope.User);
189
+ }
190
+ /**
191
+ * Toggle the display of minimap in the editor.
192
+ */
193
+ async toggleMinimap() {
194
+ const value = this.preferenceService.get('editor.minimap.enabled');
195
+ this.preferenceService.set('editor.minimap.enabled', !value, browser_1.PreferenceScope.User);
196
+ }
197
+ /**
198
+ * Toggle the rendering of whitespace in the editor.
199
+ */
200
+ async toggleRenderWhitespace() {
201
+ const renderWhitespace = this.preferenceService.get('editor.renderWhitespace');
202
+ let updatedRenderWhitespace;
203
+ if (renderWhitespace === 'none') {
204
+ updatedRenderWhitespace = 'all';
205
+ }
206
+ else {
207
+ updatedRenderWhitespace = 'none';
208
+ }
209
+ this.preferenceService.set('editor.renderWhitespace', updatedRenderWhitespace, browser_1.PreferenceScope.User);
210
+ }
211
+ onCurrentEditorChanged(editorWidget) {
212
+ this.toDisposePerCurrentEditor.dispose();
213
+ if (editorWidget) {
214
+ const { editor } = editorWidget;
215
+ this.toDisposePerCurrentEditor.pushAll([
216
+ // Instead of registering an `onCursorPositionChanged` listener, we treat the zero length selection as a cursor position change.
217
+ // Otherwise we would have two events for a single cursor change interaction.
218
+ editor.onSelectionChanged(selection => this.onSelectionChanged(editor, selection)),
219
+ editor.onDocumentContentChanged(event => this.onDocumentContentChanged(editor, event))
220
+ ]);
221
+ this.locationStack.register(navigation_location_1.NavigationLocation.create(editor, editor.selection));
222
+ }
223
+ }
224
+ onCursorPositionChanged(editor, position) {
225
+ this.locationStack.register(navigation_location_1.NavigationLocation.create(editor, position));
226
+ }
227
+ onSelectionChanged(editor, selection) {
228
+ if (this.isZeroLengthRange(selection)) {
229
+ this.onCursorPositionChanged(editor, selection.start);
230
+ }
231
+ else {
232
+ this.locationStack.register(navigation_location_1.NavigationLocation.create(editor, selection));
233
+ }
234
+ }
235
+ onDocumentContentChanged(editor, event) {
236
+ if (event.contentChanges.length > 0) {
237
+ this.locationStack.register(navigation_location_1.NavigationLocation.create(editor, event.contentChanges[0]));
238
+ }
239
+ }
240
+ /**
241
+ * `true` if the `range` argument has zero length. In other words, the `start` and the `end` positions are the same. Otherwise, `false`.
242
+ */
243
+ isZeroLengthRange(range) {
244
+ const { start, end } = range;
245
+ return start.line === end.line && start.character === end.character;
246
+ }
247
+ async storeState() {
248
+ this.storageService.setData(EditorNavigationContribution_1.ID, {
249
+ locations: this.locationStack.locations().map(navigation_location_1.NavigationLocation.toObject)
250
+ });
251
+ this.storageService.setData(EditorNavigationContribution_1.CLOSED_EDITORS_KEY, {
252
+ closedEditors: this.shouldStoreClosedEditors() ? this.locationStack.closedEditorsStack.map(navigation_location_1.RecentlyClosedEditor.toObject) : []
253
+ });
254
+ }
255
+ async restoreState() {
256
+ await this.restoreNavigationLocations();
257
+ await this.restoreClosedEditors();
258
+ }
259
+ async restoreNavigationLocations() {
260
+ const raw = await this.storageService.getData(EditorNavigationContribution_1.ID);
261
+ if (raw && raw.locations) {
262
+ const locations = [];
263
+ for (let i = 0; i < raw.locations.length; i++) {
264
+ const location = navigation_location_1.NavigationLocation.fromObject(raw.locations[i]);
265
+ if (location) {
266
+ locations.push(location);
267
+ }
268
+ else {
269
+ this.logger.warn('Could not restore the state of the editor navigation history.');
270
+ return;
271
+ }
272
+ }
273
+ this.locationStack.register(...locations);
274
+ }
275
+ }
276
+ async restoreClosedEditors() {
277
+ const raw = await this.storageService.getData(EditorNavigationContribution_1.CLOSED_EDITORS_KEY);
278
+ if (raw && raw.closedEditors) {
279
+ for (let i = 0; i < raw.closedEditors.length; i++) {
280
+ const editor = navigation_location_1.RecentlyClosedEditor.fromObject(raw.closedEditors[i]);
281
+ if (editor) {
282
+ this.locationStack.addClosedEditor(editor);
283
+ }
284
+ else {
285
+ this.logger.warn('Could not restore the state of the closed editors stack.');
286
+ }
287
+ }
288
+ }
289
+ }
290
+ isMinimapEnabled() {
291
+ return !!this.preferenceService.get('editor.minimap.enabled');
292
+ }
293
+ isRenderWhitespaceEnabled() {
294
+ const renderWhitespace = this.preferenceService.get('editor.renderWhitespace');
295
+ return renderWhitespace === 'none' ? false : true;
296
+ }
297
+ shouldStoreClosedEditors() {
298
+ return !!this.preferenceService.get('editor.history.persistClosedEditors');
299
+ }
300
+ shouldNavigateWithMouse() {
301
+ return !!this.preferenceService.get(EditorNavigationContribution_1.MOUSE_NAVIGATION_PREFERENCE);
302
+ }
303
+ isStickyScrollEnabled() {
304
+ return !!this.preferenceService.get('editor.stickyScroll.enabled');
305
+ }
306
+ };
307
+ EditorNavigationContribution.ID = 'editor-navigation-contribution';
308
+ EditorNavigationContribution.CLOSED_EDITORS_KEY = 'recently-closed-editors';
309
+ EditorNavigationContribution.MOUSE_NAVIGATION_PREFERENCE = 'workbench.editor.mouseBackForwardToNavigate';
310
+ __decorate([
311
+ (0, inversify_1.inject)(logger_1.ILogger),
312
+ __metadata("design:type", Object)
313
+ ], EditorNavigationContribution.prototype, "logger", void 0);
314
+ __decorate([
315
+ (0, inversify_1.inject)(editor_manager_1.EditorManager),
316
+ __metadata("design:type", editor_manager_1.EditorManager)
317
+ ], EditorNavigationContribution.prototype, "editorManager", void 0);
318
+ __decorate([
319
+ (0, inversify_1.inject)(navigation_location_service_1.NavigationLocationService),
320
+ __metadata("design:type", navigation_location_service_1.NavigationLocationService)
321
+ ], EditorNavigationContribution.prototype, "locationStack", void 0);
322
+ __decorate([
323
+ (0, inversify_1.inject)(storage_service_1.StorageService),
324
+ __metadata("design:type", Object)
325
+ ], EditorNavigationContribution.prototype, "storageService", void 0);
326
+ __decorate([
327
+ (0, inversify_1.inject)(browser_1.PreferenceService),
328
+ __metadata("design:type", Object)
329
+ ], EditorNavigationContribution.prototype, "preferenceService", void 0);
330
+ __decorate([
331
+ (0, inversify_1.inject)(command_1.CommandRegistry),
332
+ __metadata("design:type", command_1.CommandRegistry)
333
+ ], EditorNavigationContribution.prototype, "commandRegistry", void 0);
334
+ __decorate([
335
+ (0, inversify_1.postConstruct)(),
336
+ __metadata("design:type", Function),
337
+ __metadata("design:paramtypes", []),
338
+ __metadata("design:returntype", void 0)
339
+ ], EditorNavigationContribution.prototype, "init", null);
340
+ EditorNavigationContribution = EditorNavigationContribution_1 = __decorate([
341
+ (0, inversify_1.injectable)()
342
+ ], EditorNavigationContribution);
343
+ exports.EditorNavigationContribution = EditorNavigationContribution;
344
344
  //# sourceMappingURL=editor-navigation-contribution.js.map