Skip to content

Commit a18110a

Browse files
author
Benjamin Pasero
committed
editors - bring back close() to inputs
1 parent 99a0740 commit a18110a

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,11 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
530530
editorsToClose.push(editor.master, editor.details);
531531
}
532532

533-
// Dispose the editor when it is no longer open in any group including diff editors
533+
// Forward close to editor input for handling within
534534
editorsToClose.forEach(editorToClose => {
535-
if (!this.accessor.groups.some(groupView => groupView.group.contains(editorToClose, true /* include side by side editor master & details */))) {
536-
editorToClose.dispose();
537-
}
535+
const openedInOtherGroups = this.accessor.groups.some(groupView => groupView.group.contains(editorToClose, true /* include side by side editor master & details */));
536+
537+
editorToClose.close(this._group.id, openedInOtherGroups);
538538
});
539539

540540
/* __GDPR__

src/vs/workbench/common/editor.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,21 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
581581
return undefined;
582582
}
583583

584+
/**
585+
* Called when this input was closed in a group. The second parameter
586+
* is a hint wether the editor is still opened in other groups. This
587+
* may include normal editors as well as side-by-side or diff editors.
588+
*
589+
* Subclasses can override what should happen. By default, an editor
590+
* input will dispose when it is closed.
591+
*/
592+
close(group: GroupIdentifier, openedInOtherGroups: boolean): void {
593+
// TODO@ben revisit this behaviour, should just dispose by default after adoption
594+
if (!openedInOtherGroups) {
595+
this.dispose();
596+
}
597+
}
598+
584599
/**
585600
* Subclasses can set this to false if it does not make sense to split the editor input.
586601
*/

src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
303303
return undefined;
304304
}
305305

306+
close(group: GroupIdentifier, openedInOtherGroups: boolean): void {
307+
if (!openedInOtherGroups) {
308+
this.dispose(); // Only dispose if not opened anymore because all file inputs are shared
309+
}
310+
}
311+
306312
matches(otherInput: unknown): boolean {
307313
if (super.matches(otherInput) === true) {
308314
return true;

src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IEncodingSupport, EncodingMode, Verbosity, IModeSupport } from 'vs/workbench/common/editor';
6+
import { IEncodingSupport, EncodingMode, Verbosity, IModeSupport, GroupIdentifier } from 'vs/workbench/common/editor';
77
import { AbstractTextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput';
88
import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel';
99
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
@@ -121,6 +121,12 @@ export class UntitledTextEditorInput extends AbstractTextResourceEditorInput imp
121121
return this.modelResolve;
122122
}
123123

124+
close(group: GroupIdentifier, openedInOtherGroups: boolean): void {
125+
if (!openedInOtherGroups) {
126+
this.dispose(); // Only dispose if not opened anymore because all untitled inputs are shared
127+
}
128+
}
129+
124130
matches(otherInput: unknown): boolean {
125131
if (super.matches(otherInput) === true) {
126132
return true;

0 commit comments

Comments
 (0)