Skip to content

Commit ce708a9

Browse files
authored
editors - only close disposed editors (microsoft#186736) (microsoft#186886)
1 parent b0e5025 commit ce708a9

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/vs/workbench/browser/parts/editor/editorGroupView.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,25 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
665665
this.disposedEditorsWorker.work(editor);
666666
}
667667

668-
private handleDisposedEditors(editors: EditorInput[]): void {
668+
private handleDisposedEditors(disposedEditors: EditorInput[]): void {
669669

670670
// Split between visible and hidden editors
671671
let activeEditor: EditorInput | undefined;
672672
const inactiveEditors: EditorInput[] = [];
673-
for (const editor of editors) {
673+
for (const disposedEditor of disposedEditors) {
674+
const editorFindResult = this.model.findEditor(disposedEditor);
675+
if (!editorFindResult) {
676+
continue; // not part of the model anymore
677+
}
678+
679+
const editor = editorFindResult[0];
680+
if (!editor.isDisposed()) {
681+
continue; // editor got reopened meanwhile
682+
}
683+
674684
if (this.model.isActive(editor)) {
675685
activeEditor = editor;
676-
} else if (this.model.contains(editor)) {
686+
} else {
677687
inactiveEditors.push(editor);
678688
}
679689
}

src/vs/workbench/common/editor/editorGroupModel.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ export class EditorGroupModel extends Disposable {
869869
}
870870
}
871871

872-
indexOf(candidate: EditorInput | null, editors = this.editors, options?: IMatchEditorOptions): number {
872+
indexOf(candidate: EditorInput | IUntypedEditorInput | null, editors = this.editors, options?: IMatchEditorOptions): number {
873873
let index = -1;
874874
if (!candidate) {
875875
return index;
@@ -894,7 +894,7 @@ export class EditorGroupModel extends Disposable {
894894
return index;
895895
}
896896

897-
private findEditor(candidate: EditorInput | null, options?: IMatchEditorOptions): [EditorInput, number /* index */] | undefined {
897+
findEditor(candidate: EditorInput | null, options?: IMatchEditorOptions): [EditorInput, number /* index */] | undefined {
898898
const index = this.indexOf(candidate, this.editors, options);
899899
if (index === -1) {
900900
return undefined;
@@ -912,13 +912,7 @@ export class EditorGroupModel extends Disposable {
912912
}
913913

914914
contains(candidate: EditorInput | IUntypedEditorInput, options?: IMatchEditorOptions): boolean {
915-
for (const editor of this.editors) {
916-
if (this.matches(editor, candidate, options)) {
917-
return true;
918-
}
919-
}
920-
921-
return false;
915+
return this.indexOf(candidate, this.editors, options) !== -1;
922916
}
923917

924918
private matches(editor: EditorInput | null, candidate: EditorInput | IUntypedEditorInput | null, options?: IMatchEditorOptions): boolean {

src/vs/workbench/test/browser/parts/editor/editorGroupModel.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ suite('EditorGroupModel', () => {
814814

815815
assert.strictEqual(group.count, 1);
816816
assert.strictEqual(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 1);
817+
assert.strictEqual(group.findEditor(input1)![0], input1);
817818
assert.strictEqual(group.activeEditor, input1);
818819
assert.strictEqual(group.isActive(input1), true);
819820
assert.strictEqual(group.isPinned(input1), true);
@@ -827,6 +828,7 @@ suite('EditorGroupModel', () => {
827828
assert.strictEqual(events.activated[0].editorIndex, 0);
828829

829830
const index = group.indexOf(input1);
831+
assert.strictEqual(group.findEditor(input1)![1], index);
830832
let event = group.closeEditor(input1, EditorCloseContext.UNPIN);
831833
assert.strictEqual(event?.editor, input1);
832834
assert.strictEqual(event?.editorIndex, index);

0 commit comments

Comments
 (0)