Skip to content

Commit

Permalink
Open last seen editor, not last created
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Grant <[email protected]>
  • Loading branch information
Colin Grant authored and colin-grant-work committed Jun 3, 2021
1 parent 1e2c702 commit 9b9cc2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 9 additions & 4 deletions packages/editor/src/browser/editor-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ export class EditorManager extends NavigatableWidgetOpenHandler<EditorWidget> {
widget.onDidChangeVisibility(() => {
if (widget.isVisible) {
this.addRecentlyVisible(widget);
} else {
this.removeRecentlyVisible(widget);
}
this.updateCurrentEditor();
});
Expand Down Expand Up @@ -143,7 +141,12 @@ export class EditorManager extends NavigatableWidgetOpenHandler<EditorWidget> {
}
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;
Expand Down Expand Up @@ -278,7 +281,9 @@ export class EditorManager extends NavigatableWidgetOpenHandler<EditorWidget> {
}

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 {
Expand Down
12 changes: 8 additions & 4 deletions packages/editor/src/browser/editor-widget-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9b9cc2b

Please sign in to comment.