提交 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 { ...@@ -905,12 +905,12 @@ export class ReopenClosedEditorAction extends Action {
// Find an editor that was closed and is currently not opened in the group // Find an editor that was closed and is currently not opened in the group
let lastClosedEditor = this.historyService.popLastClosedEditor(); 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(); lastClosedEditor = this.historyService.popLastClosedEditor();
} }
if (lastClosedEditor) { if (lastClosedEditor) {
this.editorService.openEditor(lastClosedEditor, { pinned: true }); this.editorService.openEditor(lastClosedEditor.editor, { pinned: true, index: lastClosedEditor.index });
} }
return TPromise.as(false); return TPromise.as(false);
......
...@@ -831,6 +831,7 @@ export interface IEditorContext extends IEditorIdentifier { ...@@ -831,6 +831,7 @@ export interface IEditorContext extends IEditorIdentifier {
export interface IGroupEvent { export interface IGroupEvent {
editor: IEditorInput; editor: IEditorInput;
pinned: boolean; pinned: boolean;
index: number;
} }
export type GroupIdentifier = number; export type GroupIdentifier = number;
......
...@@ -346,7 +346,7 @@ export class EditorGroup implements IEditorGroup { ...@@ -346,7 +346,7 @@ export class EditorGroup implements IEditorGroup {
this.splice(index, true); this.splice(index, true);
// Event // Event
this.fireEvent(this._onEditorClosed, { editor, pinned }, true); this.fireEvent(this._onEditorClosed, { editor, pinned, index }, true);
} }
public closeEditors(except: EditorInput, direction?: Direction): void { public closeEditors(except: EditorInput, direction?: Direction): void {
......
...@@ -14,7 +14,7 @@ import {IEditor as IBaseEditor} from 'vs/platform/editor/common/editor'; ...@@ -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 {EditorInput, IGroupEvent, IEditorRegistry, Extensions} from 'vs/workbench/common/editor';
import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor'; import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; 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 {Selection} from 'vs/editor/common/core/selection';
import {IEditorInput, ITextEditorOptions} from 'vs/platform/editor/common/editor'; import {IEditorInput, ITextEditorOptions} from 'vs/platform/editor/common/editor';
import {IEventService} from 'vs/platform/event/common/event'; import {IEventService} from 'vs/platform/event/common/event';
...@@ -228,7 +228,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -228,7 +228,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private currentFileEditorState: EditorState; private currentFileEditorState: EditorState;
private history: IEditorInput[]; private history: IEditorInput[];
private recentlyClosed: IEditorInput[]; private recentlyClosed: RecentlyClosedEditorInput[];
private loaded: boolean; private loaded: boolean;
private registry: IEditorRegistry; private registry: IEditorRegistry;
...@@ -268,7 +268,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -268,7 +268,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
// Remove all inputs matching and add as last recently closed // Remove all inputs matching and add as last recently closed
this.removeFromRecentlyClosed(editor); this.removeFromRecentlyClosed(editor);
this.recentlyClosed.push(editor); this.recentlyClosed.push({ editor, index: event.index });
// Bounding // Bounding
if (this.recentlyClosed.length > HistoryService.MAX_RECENTLY_CLOSED_EDITORS) { if (this.recentlyClosed.length > HistoryService.MAX_RECENTLY_CLOSED_EDITORS) {
...@@ -283,7 +283,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -283,7 +283,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
} }
} }
public popLastClosedEditor(): IEditorInput { public popLastClosedEditor(): RecentlyClosedEditorInput {
this.ensureLoaded(); this.ensureLoaded();
return this.recentlyClosed.pop(); return this.recentlyClosed.pop();
...@@ -531,14 +531,14 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -531,14 +531,14 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
let restored = false; let restored = false;
this.recentlyClosed.forEach((e, i) => { this.recentlyClosed.forEach((e, i) => {
if (e.matches(input)) { if (e.editor.matches(input)) {
if (!restored) { if (!restored) {
restoredInput = this.restoreInput(input); restoredInput = this.restoreInput(input);
restored = true; restored = true;
} }
if (restoredInput) { if (restoredInput) {
this.recentlyClosed[i] = restoredInput; this.recentlyClosed[i].editor = restoredInput;
} else { } else {
this.stack.splice(i, 1); this.stack.splice(i, 1);
} }
...@@ -573,7 +573,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -573,7 +573,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private removeFromRecentlyClosed(input: IEditorInput): void { private removeFromRecentlyClosed(input: IEditorInput): void {
this.recentlyClosed.forEach((e, i) => { this.recentlyClosed.forEach((e, i) => {
if (e.matches(input)) { if (e.editor.matches(input)) {
this.recentlyClosed.splice(i, 1); this.recentlyClosed.splice(i, 1);
} }
}); });
......
...@@ -9,6 +9,11 @@ import {IEditorInput} from 'vs/platform/editor/common/editor'; ...@@ -9,6 +9,11 @@ import {IEditorInput} from 'vs/platform/editor/common/editor';
export const IHistoryService = createDecorator<IHistoryService>('historyService'); export const IHistoryService = createDecorator<IHistoryService>('historyService');
export class RecentlyClosedEditorInput {
editor: IEditorInput;
index: number;
}
export interface IHistoryService { export interface IHistoryService {
_serviceBrand: ServiceIdentifier<any>; _serviceBrand: ServiceIdentifier<any>;
...@@ -16,7 +21,7 @@ export interface IHistoryService { ...@@ -16,7 +21,7 @@ export interface IHistoryService {
/** /**
* Removes and returns the last closed editor if any. * Removes and returns the last closed editor if any.
*/ */
popLastClosedEditor(): IEditorInput; popLastClosedEditor(): RecentlyClosedEditorInput;
/** /**
* Navigate forwards in history. * Navigate forwards in history.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册