diff --git a/src/vs/base/browser/ui/grid/gridview.ts b/src/vs/base/browser/ui/grid/gridview.ts index fce3c00e03f1f..c00b178640474 100644 --- a/src/vs/base/browser/ui/grid/gridview.ts +++ b/src/vs/base/browser/ui/grid/gridview.ts @@ -467,7 +467,7 @@ export class GridView implements IDisposable { const sibling = parent.children[0]; parent.removeChild(0); - const sizes = grandParent.children.map(c => c.size); + const sizes = grandParent.children.map((_, i) => grandParent.getChildSize(i)); grandParent.removeChild(parentIndex, sizing); if (sibling instanceof BranchNode) { @@ -477,15 +477,15 @@ export class GridView implements IDisposable { const child = sibling.children[i]; grandParent.addChild(child, child.size, parentIndex + i); } - - for (let i = 0; i < sizes.length; i++) { - grandParent.resizeChild(i, sizes[i]); - } } else { const newSibling = new LeafNode(sibling.view, orthogonal(sibling.orientation), sibling.size); grandParent.addChild(newSibling, sibling.orthogonalSize, parentIndex); } + for (let i = 0; i < sizes.length; i++) { + grandParent.resizeChild(i, sizes[i]); + } + return node.view; } diff --git a/src/vs/base/test/browser/ui/grid/grid.test.ts b/src/vs/base/test/browser/ui/grid/grid.test.ts index 175b7abeed67f..15fa42d596356 100644 --- a/src/vs/base/test/browser/ui/grid/grid.test.ts +++ b/src/vs/base/test/browser/ui/grid/grid.test.ts @@ -264,6 +264,30 @@ suite('Grid', function () { assert.deepEqual(view2.size, [200, 600]); assert.deepEqual(view4.size, [200, 600]); }); + + test('sizing should be correct after branch demotion #50675', function () { + const view1 = new TestView(50, Number.MAX_VALUE, 50, Number.MAX_VALUE); + const grid = new Grid(container, view1); + grid.layout(800, 600); + + const view2 = new TestView(50, Number.MAX_VALUE, 50, Number.MAX_VALUE); + grid.addView(view2, Sizing.Distribute, view1, Direction.Down); + + const view3 = new TestView(50, Number.MAX_VALUE, 50, Number.MAX_VALUE); + grid.addView(view3, Sizing.Distribute, view2, Direction.Down); + + const view4 = new TestView(50, Number.MAX_VALUE, 50, Number.MAX_VALUE); + grid.addView(view4, Sizing.Distribute, view3, Direction.Right); + assert.deepEqual(view1.size, [800, 200]); + assert.deepEqual(view2.size, [800, 200]); + assert.deepEqual(view3.size, [400, 200]); + assert.deepEqual(view4.size, [400, 200]); + + grid.removeView(view3, Sizing.Distribute); + assert.deepEqual(view1.size, [800, 200]); + assert.deepEqual(view2.size, [800, 200]); + assert.deepEqual(view4.size, [800, 200]); + }); }); class TestSerializableView extends TestView implements ISerializableView {