提交 459b4f8e 编写于 作者: B Benjamin Pasero 提交者: GitHub

Merge pull request #11076 from sprinkle131313/master

Implements recently closed editors opening at same position as they were closed.
......@@ -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);
......
......@@ -831,6 +831,7 @@ export interface IEditorContext extends IEditorIdentifier {
export interface IGroupEvent {
editor: IEditorInput;
pinned: boolean;
index: number;
}
export type GroupIdentifier = number;
......
......@@ -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 {
......
......@@ -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);
}
});
......
......@@ -9,6 +9,11 @@ import {IEditorInput} from 'vs/platform/editor/common/editor';
export const IHistoryService = createDecorator<IHistoryService>('historyService');
export class RecentlyClosedEditorInput {
editor: IEditorInput;
index: number;
}
export interface IHistoryService {
_serviceBrand: ServiceIdentifier<any>;
......@@ -16,7 +21,7 @@ export interface IHistoryService {
/**
* Removes and returns the last closed editor if any.
*/
popLastClosedEditor(): IEditorInput;
popLastClosedEditor(): RecentlyClosedEditorInput;
/**
* Navigate forwards in history.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册