diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index 591f2936763dad18f786baacb9e8602c7436191a..b2a06eb53529d3b4452ad642feb64ab6ca814e87 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -905,12 +905,12 @@ export class ReopenClosedEditorAction extends Action { // Find an editor that was closed and is currently not opened in the group let lastClosedEditor = this.historyService.popLastClosedEditor(); - while (lastClosedEditor && stacks.activeGroup && stacks.activeGroup.indexOf(lastClosedEditor) >= 0) { + while (lastClosedEditor && stacks.activeGroup && stacks.activeGroup.indexOf(lastClosedEditor.editor) >= 0) { lastClosedEditor = this.historyService.popLastClosedEditor(); } if (lastClosedEditor) { - this.editorService.openEditor(lastClosedEditor, { pinned: true }); + this.editorService.openEditor(lastClosedEditor.editor, { pinned: true, index: lastClosedEditor.index }); } return TPromise.as(false); diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 265a4046cba22531b5cd76d16111c25645d7143b..5419531eeb615f9bb9068624e30850c36cff782c 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -831,6 +831,7 @@ export interface IEditorContext extends IEditorIdentifier { export interface IGroupEvent { editor: IEditorInput; pinned: boolean; + index: number; } export type GroupIdentifier = number; diff --git a/src/vs/workbench/common/editor/editorStacksModel.ts b/src/vs/workbench/common/editor/editorStacksModel.ts index 7d5ce5cf67300ab7980dc5bc1ce82b4fa16ac11c..41767e63e9782ce876ff4f7a0b805574d035d79c 100644 --- a/src/vs/workbench/common/editor/editorStacksModel.ts +++ b/src/vs/workbench/common/editor/editorStacksModel.ts @@ -346,7 +346,7 @@ export class EditorGroup implements IEditorGroup { this.splice(index, true); // Event - this.fireEvent(this._onEditorClosed, { editor, pinned }, true); + this.fireEvent(this._onEditorClosed, { editor, pinned, index }, true); } public closeEditors(except: EditorInput, direction?: Direction): void { diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index 9fafe92ad3c00693da823a02e39d3f211078eca4..4f59957f8bede444e2bef8d3c88edb1aa495ce92 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -14,7 +14,7 @@ import {IEditor as IBaseEditor} from 'vs/platform/editor/common/editor'; import {EditorInput, IGroupEvent, IEditorRegistry, Extensions} from 'vs/workbench/common/editor'; import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; -import {IHistoryService} from 'vs/workbench/services/history/common/history'; +import {RecentlyClosedEditorInput, IHistoryService} from 'vs/workbench/services/history/common/history'; import {Selection} from 'vs/editor/common/core/selection'; import {IEditorInput, ITextEditorOptions} from 'vs/platform/editor/common/editor'; import {IEventService} from 'vs/platform/event/common/event'; @@ -228,7 +228,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic private currentFileEditorState: EditorState; private history: IEditorInput[]; - private recentlyClosed: IEditorInput[]; + private recentlyClosed: RecentlyClosedEditorInput[]; private loaded: boolean; private registry: IEditorRegistry; @@ -268,7 +268,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic // Remove all inputs matching and add as last recently closed this.removeFromRecentlyClosed(editor); - this.recentlyClosed.push(editor); + this.recentlyClosed.push({ editor, index: event.index }); // Bounding if (this.recentlyClosed.length > HistoryService.MAX_RECENTLY_CLOSED_EDITORS) { @@ -283,7 +283,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic } } - public popLastClosedEditor(): IEditorInput { + public popLastClosedEditor(): RecentlyClosedEditorInput { this.ensureLoaded(); return this.recentlyClosed.pop(); @@ -531,14 +531,14 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic let restored = false; this.recentlyClosed.forEach((e, i) => { - if (e.matches(input)) { + if (e.editor.matches(input)) { if (!restored) { restoredInput = this.restoreInput(input); restored = true; } if (restoredInput) { - this.recentlyClosed[i] = restoredInput; + this.recentlyClosed[i].editor = restoredInput; } else { this.stack.splice(i, 1); } @@ -573,7 +573,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic private removeFromRecentlyClosed(input: IEditorInput): void { this.recentlyClosed.forEach((e, i) => { - if (e.matches(input)) { + if (e.editor.matches(input)) { this.recentlyClosed.splice(i, 1); } }); diff --git a/src/vs/workbench/services/history/common/history.ts b/src/vs/workbench/services/history/common/history.ts index 6ccfd7f15667dea38cc46c35455c663116b8d541..1725ce9541df3228ecba5e97ece81082057f11b3 100644 --- a/src/vs/workbench/services/history/common/history.ts +++ b/src/vs/workbench/services/history/common/history.ts @@ -9,6 +9,11 @@ import {IEditorInput} from 'vs/platform/editor/common/editor'; export const IHistoryService = createDecorator('historyService'); +export class RecentlyClosedEditorInput { + editor: IEditorInput; + index: number; +} + export interface IHistoryService { _serviceBrand: ServiceIdentifier; @@ -16,7 +21,7 @@ export interface IHistoryService { /** * Removes and returns the last closed editor if any. */ - popLastClosedEditor(): IEditorInput; + popLastClosedEditor(): RecentlyClosedEditorInput; /** * Navigate forwards in history.