|
1 |
| -import { injectable } from '@theia/core/shared/inversify'; |
| 1 | +import { inject, injectable } from '@theia/core/shared/inversify'; |
2 | 2 | import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
|
3 | 3 | import { ShellLayoutRestorer as TheiaShellLayoutRestorer } from '@theia/core/lib/browser/shell/shell-layout-restorer';
|
| 4 | +import { EditorManager } from '@theia/editor/lib/browser'; |
4 | 5 |
|
5 | 6 | @injectable()
|
6 | 7 | export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
|
| 8 | + // The editor manager is unused in the layout restorer. |
| 9 | + // We inject the editor manager to achieve better logging when filtering duplicate editor tabs. |
| 10 | + // Feel free to remove it in later IDE2 releases if the duplicate editor tab issues do not occur anymore. |
| 11 | + @inject(EditorManager) |
| 12 | + private readonly editorManager: EditorManager; |
| 13 | + |
7 | 14 | // Workaround for https://github.com/eclipse-theia/theia/issues/6579.
|
8 | 15 | async storeLayoutAsync(app: FrontendApplication): Promise<void> {
|
9 | 16 | if (this.shouldStoreLayout) {
|
@@ -35,21 +42,36 @@ export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
|
35 | 42 |
|
36 | 43 | const layoutData = await this.inflate(serializedLayoutData);
|
37 | 44 | // workaround to remove duplicated tabs
|
| 45 | + console.log( |
| 46 | + '>>> Filtering persisted layout data to eliminate duplicate editor tabs...' |
| 47 | + ); |
38 | 48 | const filesUri: string[] = [];
|
39 | 49 | if ((layoutData as any)?.mainPanel?.main?.widgets) {
|
40 | 50 | (layoutData as any).mainPanel.main.widgets = (
|
41 | 51 | layoutData as any
|
42 | 52 | ).mainPanel.main.widgets.filter((widget: any) => {
|
43 | 53 | const uri = widget.getResourceUri().toString();
|
44 | 54 | if (filesUri.includes(uri)) {
|
| 55 | + console.log(`[SKIP]: Already visited editor URI: '${uri}'.`); |
45 | 56 | return false;
|
46 | 57 | }
|
| 58 | + console.log(`[OK]: Visited editor URI: '${uri}'.`); |
47 | 59 | filesUri.push(uri);
|
48 | 60 | return true;
|
49 | 61 | });
|
50 | 62 | }
|
| 63 | + console.log('<<< Filtered the layout data before restoration.'); |
51 | 64 |
|
52 | 65 | await app.shell.setLayoutData(layoutData);
|
| 66 | + const allOpenedEditors = this.editorManager.all; |
| 67 | + // If any editor was visited during the layout data filtering, |
| 68 | + // but the editor manager does not know about opened editors, then |
| 69 | + // the IDE2 will show duplicate editors. |
| 70 | + if (filesUri.length && !allOpenedEditors.length) { |
| 71 | + console.warn( |
| 72 | + 'Inconsistency detected between the editor manager and the restored layout data. Editors were detected to be open in the layout data from the previous session, but the editor manager does not know about the opened editor.' |
| 73 | + ); |
| 74 | + } |
53 | 75 | this.logger.info('<<< The layout has been successfully restored.');
|
54 | 76 | return true;
|
55 | 77 | }
|
|
0 commit comments