Skip to content

Commit 4f991f8

Browse files
authored
Fix View: Toggle Editor Group Sizes (microsoft#154467)
Figuring out whether a view was maximized was faulty, since it doesn't necessarily mean that all other views are minimized. Pushed the logic down to grid/gridview/splitview so it's now just simple widget API. Fixes: microsoft#154068
1 parent fc10a34 commit 4f991f8

File tree

10 files changed

+64
-33
lines changed

10 files changed

+64
-33
lines changed

src/vs/base/browser/ui/grid/grid.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,16 @@ export class Grid<T extends IView = IView> extends Disposable {
527527
return this.gridview.resizeView(location, size);
528528
}
529529

530+
/**
531+
* Returns whether all other {@link IView views} are at their minimum size.
532+
*
533+
* @param view The reference {@link IView view}.
534+
*/
535+
isViewSizeMaximized(view: T): boolean {
536+
const location = this.getViewLocation(view);
537+
return this.gridview.isViewSizeMaximized(location);
538+
}
539+
530540
/**
531541
* Get the size of a {@link IView view}.
532542
*

src/vs/base/browser/ui/grid/gridview.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
592592
this.splitview.resizeView(index, size);
593593
}
594594

595+
isChildSizeMaximized(index: number): boolean {
596+
return this.splitview.isViewSizeMaximized(index);
597+
}
598+
595599
distributeViewSizes(recursive = false): void {
596600
this.splitview.distributeViewSizes();
597601

@@ -1431,6 +1435,27 @@ export class GridView implements IDisposable {
14311435
}
14321436
}
14331437

1438+
/**
1439+
* Returns whether all other {@link IView views} are at their minimum size.
1440+
*
1441+
* @param location The {@link GridLocation location} of the view.
1442+
*/
1443+
isViewSizeMaximized(location: GridLocation): boolean {
1444+
const [ancestors, node] = this.getNode(location);
1445+
1446+
if (!(node instanceof LeafNode)) {
1447+
throw new Error('Invalid location');
1448+
}
1449+
1450+
for (let i = 0; i < ancestors.length; i++) {
1451+
if (!ancestors[i].isChildSizeMaximized(location[i])) {
1452+
return false;
1453+
}
1454+
}
1455+
1456+
return true;
1457+
}
1458+
14341459
/**
14351460
* Distribute the size among all {@link IView views} within the entire
14361461
* grid or within a single {@link SplitView}.

src/vs/base/browser/ui/splitview/splitview.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,23 @@ export class SplitView<TLayoutContext = undefined> extends Disposable {
931931
this.state = State.Idle;
932932
}
933933

934+
/**
935+
* Returns whether all other {@link IView views} are at their minimum size.
936+
*/
937+
isViewSizeMaximized(index: number): boolean {
938+
if (index < 0 || index >= this.viewItems.length) {
939+
return false;
940+
}
941+
942+
for (const item of this.viewItems) {
943+
if (item !== this.viewItems[index] && item.size > item.minimumSize) {
944+
return false;
945+
}
946+
}
947+
948+
return true;
949+
}
950+
934951
/**
935952
* Distribute the entire {@link SplitView} size among all {@link IView views}.
936953
*/

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ export interface IEditorGroupView extends IDisposable, ISerializableView, IEdito
135135

136136
readonly titleHeight: IEditorGroupTitleHeight;
137137

138-
readonly isMinimized: boolean;
139-
140138
readonly disposed: boolean;
141139

142140
setActive(isActive: boolean): void;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ export class MinimizeOtherGroupsAction extends Action {
10231023
}
10241024

10251025
override async run(): Promise<void> {
1026-
this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
1026+
this.editorGroupService.arrangeGroups(GroupsArrangement.MAXIMIZE);
10271027
}
10281028
}
10291029

@@ -1074,7 +1074,7 @@ export class MaximizeGroupAction extends Action {
10741074
if (this.editorService.activeEditor) {
10751075
this.layoutService.setPartHidden(true, Parts.SIDEBAR_PART);
10761076
this.layoutService.setPartHidden(true, Parts.AUXILIARYBAR_PART);
1077-
this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
1077+
this.editorGroupService.arrangeGroups(GroupsArrangement.MAXIMIZE);
10781078
}
10791079
}
10801080
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
781781
return this.titleAreaControl.getHeight();
782782
}
783783

784-
get isMinimized(): boolean {
785-
if (!this.dimension) {
786-
return false;
787-
}
788-
789-
return this.dimension.width === this.minimumWidth || this.dimension.height === this.minimumHeight;
790-
}
791-
792784
notifyIndexChanged(newIndex: number): void {
793785
if (this._index !== newIndex) {
794786
this._index = newIndex;

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,32 +362,22 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
362362
case GroupsArrangement.EVEN:
363363
this.gridWidget.distributeViewSizes();
364364
break;
365-
case GroupsArrangement.MINIMIZE_OTHERS:
365+
case GroupsArrangement.MAXIMIZE:
366366
this.gridWidget.maximizeViewSize(target);
367367
break;
368368
case GroupsArrangement.TOGGLE:
369369
if (this.isGroupMaximized(target)) {
370370
this.arrangeGroups(GroupsArrangement.EVEN);
371371
} else {
372-
this.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
372+
this.arrangeGroups(GroupsArrangement.MAXIMIZE);
373373
}
374374

375375
break;
376376
}
377377
}
378378

379-
private isGroupMaximized(targetGroup: IEditorGroupView): boolean {
380-
for (const group of this.groups) {
381-
if (group === targetGroup) {
382-
continue; // ignore target group
383-
}
384-
385-
if (!group.isMinimized) {
386-
return false; // target cannot be maximized if one group is not minimized
387-
}
388-
}
389-
390-
return true;
379+
isGroupMaximized(targetGroup: IEditorGroupView): boolean {
380+
return this.gridWidget.isViewSizeMaximized(targetGroup);
391381
}
392382

393383
setGroupOrientation(orientation: GroupOrientation): void {
@@ -609,7 +599,7 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
609599
if (this.gridWidget) {
610600
const viewSize = this.gridWidget.getViewSize(group);
611601
if (viewSize.width === group.minimumWidth || viewSize.height === group.minimumHeight) {
612-
this.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS, group);
602+
this.arrangeGroups(GroupsArrangement.MAXIMIZE, group);
613603
}
614604
}
615605
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const enum GroupsArrangement {
4747
* Make the current active group consume the maximum
4848
* amount of space possible.
4949
*/
50-
MINIMIZE_OTHERS,
50+
MAXIMIZE,
5151

5252
/**
5353
* Size all groups evenly.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ suite('EditorService', () => {
16611661
editor = await service.openEditor(input2, { pinned: true, activation: EditorActivation.ACTIVATE }, sideGroup);
16621662
assert.strictEqual(part.activeGroup, sideGroup);
16631663

1664-
part.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
1664+
part.arrangeGroups(GroupsArrangement.MAXIMIZE);
16651665
editor = await service.openEditor(input1, { pinned: true, preserveFocus: true, activation: EditorActivation.RESTORE }, rootGroup);
16661666
assert.strictEqual(part.activeGroup, sideGroup);
16671667
});
@@ -1681,13 +1681,13 @@ suite('EditorService', () => {
16811681
assert.strictEqual(part.activeGroup, sideGroup);
16821682
assert.notStrictEqual(rootGroup, sideGroup);
16831683

1684-
part.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS, part.activeGroup);
1684+
part.arrangeGroups(GroupsArrangement.MAXIMIZE, part.activeGroup);
16851685

16861686
await rootGroup.closeEditor(input2);
16871687
assert.strictEqual(part.activeGroup, sideGroup);
16881688

1689-
assert.strictEqual(rootGroup.isMinimized, true);
1690-
assert.strictEqual(part.activeGroup.isMinimized, false);
1689+
assert(!part.isGroupMaximized(rootGroup));
1690+
assert(part.isGroupMaximized(part.activeGroup));
16911691
});
16921692

16931693
test('active editor change / visible editor change events', async function () {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,6 @@ export class TestEditorGroupView implements IEditorGroupView {
853853
titleHeight!: IEditorGroupTitleHeight;
854854

855855
isEmpty = true;
856-
isMinimized = false;
857856

858857
onWillDispose: Event<void> = Event.None;
859858
onDidModelChange: Event<IGroupModelChangeEvent> = Event.None;

0 commit comments

Comments
 (0)