提交 3d88abfe 编写于 作者: B Benjamin Pasero

workbench.action.reopenClosedEditor should work with preview editors (fixes #37849)

上级 04659ba3
......@@ -791,7 +791,7 @@ export interface IEditorContext extends IEditorIdentifier {
}
export interface IEditorCloseEvent extends IEditorIdentifier {
pinned: boolean;
replaced: boolean;
index: number;
}
......
......@@ -342,8 +342,8 @@ export class EditorGroup implements IEditorGroup {
}));
}
public replaceEditor(toReplace: EditorInput, replaceWidth: EditorInput, replaceIndex: number, openNext = true): void {
const event = this.doCloseEditor(toReplace, openNext); // optimization to prevent multiple setActive() in one call
private replaceEditor(toReplace: EditorInput, replaceWidth: EditorInput, replaceIndex: number, openNext = true): void {
const event = this.doCloseEditor(toReplace, openNext, true); // optimization to prevent multiple setActive() in one call
// We want to first add the new editor into our model before emitting the close event because
// firing the close event can trigger a dispose on the same editor that is now being added.
......@@ -356,14 +356,14 @@ export class EditorGroup implements IEditorGroup {
}
public closeEditor(editor: EditorInput, openNext = true): void {
const event = this.doCloseEditor(editor, openNext);
const event = this.doCloseEditor(editor, openNext, false);
if (event) {
this.fireEvent(this._onEditorClosed, event, true);
}
}
private doCloseEditor(editor: EditorInput, openNext = true): EditorCloseEvent {
private doCloseEditor(editor: EditorInput, openNext: boolean, replaced: boolean): EditorCloseEvent {
const index = this.indexOf(editor);
if (index === -1) {
return null; // not found
......@@ -384,17 +384,15 @@ export class EditorGroup implements IEditorGroup {
}
// Preview Editor closed
let pinned = true;
if (this.matches(this.preview, editor)) {
this.preview = null;
pinned = false;
}
// Remove from arrays
this.splice(index, true);
// Event
return { editor, pinned, index, group: this };
return { editor, replaced, index, group: this };
}
public closeEditors(except: EditorInput, direction?: Direction): void {
......
......@@ -244,8 +244,8 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private onEditorClosed(event: IEditorCloseEvent): void {
// Track closing of pinned editor to support to reopen closed editors
if (event.pinned) {
// Track closing of editor to support to reopen closed editors (unless editor was replaced)
if (!event.replaced) {
const resource = event.editor ? event.editor.getResource() : void 0;
const supportsReopen = resource && this.fileService.canHandleResource(resource); // we only support file'ish things to reopen
if (supportsReopen) {
......
......@@ -506,7 +506,7 @@ suite('Editor Stacks Model', () => {
assert.equal(group.activeEditor, void 0);
assert.equal(events.closed[0].editor, input1);
assert.equal(events.closed[0].index, 0);
assert.equal(events.closed[0].pinned, true);
assert.equal(events.closed[0].replaced, false);
// Active && Preview
const input2 = input();
......@@ -529,7 +529,7 @@ suite('Editor Stacks Model', () => {
assert.equal(group.activeEditor, void 0);
assert.equal(events.closed[1].editor, input2);
assert.equal(events.closed[1].index, 0);
assert.equal(events.closed[1].pinned, false);
assert.equal(events.closed[1].replaced, false);
group.closeEditor(input2);
assert.equal(group.count, 0);
......@@ -748,6 +748,8 @@ suite('Editor Stacks Model', () => {
assert.equal(events.opened[2], input3);
assert.equal(events.closed[0].editor, input1);
assert.equal(events.closed[1].editor, input2);
assert.equal(events.closed[0].replaced, true);
assert.equal(events.closed[1].replaced, true);
const mru = group.getEditors(true);
assert.equal(mru[0], input3);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册