From 9b9cc2ba4864a45edcb34b459485d8aa54268a5d Mon Sep 17 00:00:00 2001 From: Colin Grant Date: Tue, 1 Jun 2021 13:59:05 -0500 Subject: [PATCH] Open last seen editor, not last created Signed-off-by: Colin Grant --- packages/editor/src/browser/editor-manager.ts | 13 +++++++++---- .../editor/src/browser/editor-widget-factory.ts | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/editor/src/browser/editor-manager.ts b/packages/editor/src/browser/editor-manager.ts index 0f960b2adb9a4..a4acf0515430a 100644 --- a/packages/editor/src/browser/editor-manager.ts +++ b/packages/editor/src/browser/editor-manager.ts @@ -64,8 +64,6 @@ export class EditorManager extends NavigatableWidgetOpenHandler { widget.onDidChangeVisibility(() => { if (widget.isVisible) { this.addRecentlyVisible(widget); - } else { - this.removeRecentlyVisible(widget); } this.updateCurrentEditor(); }); @@ -143,7 +141,12 @@ export class EditorManager extends NavigatableWidgetOpenHandler { } protected updateActiveEditor(): void { const widget = this.shell.activeWidget; - this.setActiveEditor(widget instanceof EditorWidget ? widget : undefined); + if (widget instanceof EditorWidget) { + this.addRecentlyVisible(widget); + this.setActiveEditor(widget); + } else { + this.setActiveEditor(undefined); + } } protected _currentEditor: EditorWidget | undefined; @@ -278,7 +281,9 @@ export class EditorManager extends NavigatableWidgetOpenHandler { } protected getCounterForUri(uri: URI): number | undefined { - return this.editorCounters.get(uri.toString()); + const idWithoutCounter = EditorWidgetFactory.createID(uri); + const counterOfMostRecentlyVisibleEditor = this.recentlyVisibleIds.find(id => id.startsWith(idWithoutCounter))?.slice(idWithoutCounter.length + 1); + return counterOfMostRecentlyVisibleEditor === undefined ? undefined : parseInt(counterOfMostRecentlyVisibleEditor); } protected getOrCreateCounterForUri(uri: URI): number { diff --git a/packages/editor/src/browser/editor-widget-factory.ts b/packages/editor/src/browser/editor-widget-factory.ts index 5cf0dc3a6681a..663bd1e7260c7 100644 --- a/packages/editor/src/browser/editor-widget-factory.ts +++ b/packages/editor/src/browser/editor-widget-factory.ts @@ -24,6 +24,12 @@ import { TextEditorProvider } from './editor'; @injectable() export class EditorWidgetFactory implements WidgetFactory { + static createID(uri: URI, counter?: number): string { + return EditorWidgetFactory.ID + + `:${uri.toString()}` + + (counter !== undefined ? `:${counter}` : ''); + } + static ID = 'code-editor-opener'; readonly id = EditorWidgetFactory.ID; @@ -54,10 +60,8 @@ export class EditorWidgetFactory implements WidgetFactory { }); newEditor.onDispose(() => labelListener.dispose()); - newEditor.id = this.id + ':' + uri.toString(); - if (options?.counter !== undefined) { - newEditor.id += `:${options.counter}`; - } + newEditor.id = EditorWidgetFactory.createID(uri, options?.counter); + newEditor.title.closable = true; return newEditor; }