Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aux window - do not close empty main window when aux windows are around with editors #198127

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/vs/workbench/electron-sandbox/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ export class NativeWindow extends BaseWindow {
}
}));

// Listen to visible editor changes (debounced)
this._register(Event.debounce(this.editorService.onDidVisibleEditorsChange, () => undefined, 50, undefined, undefined, undefined, this._store)(() => this.onDidChangeVisibleEditors()));
// Listen to visible editor changes (debounced in case a new editor opens immediately after)
this._register(Event.debounce(this.editorService.onDidVisibleEditorsChange, () => undefined, 0, undefined, undefined, undefined, this._store)(() => this.maybeCloseWindow()));

// Listen to editor closing (if we run with --wait)
const filesToWait = this.environmentService.filesToWait;
Expand Down Expand Up @@ -598,20 +598,24 @@ export class NativeWindow extends BaseWindow {
this.nativeHostService.setMinimumSize(minWidth, undefined);
}

private onDidChangeVisibleEditors(): void {
private maybeCloseWindow(): void {
const closeWhenEmpty = this.configurationService.getValue('window.closeWhenEmpty') || this.environmentService.args.wait;
if (!closeWhenEmpty) {
return; // return early if configured to not close when empty
}

// Close empty editor groups based on setting and environment
for (const editorPart of this.editorGroupService.parts) {
if (editorPart.groups.some(group => !group.isEmpty)) {
continue; // not empty
}

let closeWhenEmpty = this.configurationService.getValue('window.closeWhenEmpty') || this.environmentService.args.wait;
if (editorPart === this.editorGroupService.mainPart && (this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY || this.environmentService.isExtensionDevelopment)) {
closeWhenEmpty = false; // disabled for main part when window is not empty or extension development
}
if (!closeWhenEmpty) {
continue; // not enabled to close when empty
if (editorPart === this.editorGroupService.mainPart && (
this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY || // only for empty windows
this.environmentService.isExtensionDevelopment || // not when developing an extension
this.editorService.visibleEditors.length > 0 // not when there are still editors open in other windows
)) {
continue;
}

if (editorPart === this.editorGroupService.mainPart) {
Expand Down