Skip to content

Commit a8edb8f

Browse files
authored
Support Centered Layout with Maximized Group (microsoft#201229)
* support centered layout with maximize group * fix and add tests
1 parent deebd4f commit a8edb8f

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

src/vs/workbench/browser/layout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
363363
// Group changes
364364
this._register(this.editorGroupService.mainPart.onDidAddGroup(() => this.centerMainEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED))));
365365
this._register(this.editorGroupService.mainPart.onDidRemoveGroup(() => this.centerMainEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED))));
366+
this._register(this.editorGroupService.mainPart.onDidChangeGroupMaximized(() => this.centerMainEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED))));
366367

367368
// Prevent workbench from scrolling #55456
368369
this._register(addDisposableListener(this.mainContainer, EventType.SCROLL, () => this.mainContainer.scrollTop = 0));
@@ -1600,7 +1601,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
16001601
const isCenteredLayoutAutoResizing = this.configurationService.getValue('workbench.editor.centeredLayoutAutoResize');
16011602
if (
16021603
isCenteredLayoutAutoResizing &&
1603-
(this.editorGroupService.mainPart.groups.length > 1 || isEditorComplex)
1604+
((this.editorGroupService.mainPart.groups.length > 1 && !this.editorGroupService.mainPart.hasMaximizedGroup()) || isEditorComplex)
16041605
) {
16051606
active = false; // disable centered layout for complex editors or when there is more than one group
16061607
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {
424424
this._activeGroup.focus(); // When making views visible the focus can be affected, so restore it
425425
}
426426

427-
private hasMaximizedGroup(): boolean {
427+
hasMaximizedGroup(): boolean {
428428
return this.gridWidget.hasMaximizedView();
429429
}
430430

@@ -1129,10 +1129,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {
11291129
}
11301130

11311131
centerLayout(active: boolean): void {
1132-
if (this.hasMaximizedGroup()) {
1133-
this.unmaximizeGroup();
1134-
}
1135-
11361132
this.centeredLayoutWidget.activate(active);
11371133

11381134
this._activeGroup.focus();

src/vs/workbench/services/editor/common/editorGroupsService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ export interface IEditorPart extends IEditorGroupsContainer {
448448
*/
449449
readonly hasRestorableState: boolean;
450450

451+
/**
452+
* Find out if an editor group is currently maximized.
453+
*/
454+
hasMaximizedGroup(): boolean;
455+
451456
/**
452457
* Enable or disable centered editor layout.
453458
*/

src/vs/workbench/services/editor/test/browser/editorGroupsService.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,9 @@ suite('EditorGroupsService', () => {
17761776
const rootGroup = part.activeGroup;
17771777
const editorPartSize = part.getSize(rootGroup);
17781778

1779+
// If there is only one group, it should not be considered maximized
1780+
assert.strictEqual(part.hasMaximizedGroup(), false);
1781+
17791782
const rightGroup = part.addGroup(rootGroup, GroupDirection.RIGHT);
17801783
const rightBottomGroup = part.addGroup(rightGroup, GroupDirection.DOWN);
17811784

@@ -1788,8 +1791,12 @@ suite('EditorGroupsService', () => {
17881791
maximizedValue = maximized;
17891792
});
17901793

1794+
assert.strictEqual(part.hasMaximizedGroup(), false);
1795+
17911796
part.arrangeGroups(GroupsArrangement.MAXIMIZE, rootGroup);
17921797

1798+
assert.strictEqual(part.hasMaximizedGroup(), true);
1799+
17931800
// getSize()
17941801
assert.deepStrictEqual(part.getSize(rootGroup), editorPartSize);
17951802
assert.deepStrictEqual(part.getSize(rightGroup), { width: 0, height: 0 });
@@ -1799,6 +1806,8 @@ suite('EditorGroupsService', () => {
17991806

18001807
part.toggleMaximizeGroup();
18011808

1809+
assert.strictEqual(part.hasMaximizedGroup(), false);
1810+
18021811
// Size is restored
18031812
assert.deepStrictEqual(part.getSize(rootGroup), sizeRootGroup);
18041813
assert.deepStrictEqual(part.getSize(rightGroup), sizeRightGroup);

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ export class TestEditorGroupsService implements IEditorGroupsService {
865865
setSize(_group: number | IEditorGroup, _size: { width: number; height: number }): void { }
866866
arrangeGroups(_arrangement: GroupsArrangement): void { }
867867
toggleMaximizeGroup(): void { }
868+
hasMaximizedGroup(): boolean { throw new Error('not implemented'); }
868869
toggleExpandGroup(): void { }
869870
applyLayout(_layout: EditorGroupLayout): void { }
870871
getLayout(): EditorGroupLayout { throw new Error('not implemented'); }

0 commit comments

Comments
 (0)