Skip to content

Commit

Permalink
grid keep sizing after branch node demotion
Browse files Browse the repository at this point in the history
fixes #50564
  • Loading branch information
joaomoreno committed May 30, 2018
1 parent 3f895da commit d88d83a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/vs/base/browser/ui/grid/gridview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,21 @@ export class GridView implements IDisposable {

const sibling = parent.children[0];
parent.removeChild(0);

const sizes = grandParent.children.map(c => c.size);
grandParent.removeChild(parentIndex, sizing);

if (sibling instanceof BranchNode) {
sizes.splice(parentIndex, 1, ...sibling.children.map(c => c.size));

for (let i = 0; i < sibling.children.length; i++) {
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);
Expand Down
24 changes: 24 additions & 0 deletions src/vs/base/test/browser/ui/grid/grid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@ suite('Grid', function () {
assert.deepEqual(view4.size, [400, 300]);
assert.deepEqual(view5.size, [200, 300]);
});

test('sizing should be correct after branch demotion #50564', 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.Split, view1, Direction.Right);

const view3 = new TestView(50, Number.MAX_VALUE, 50, Number.MAX_VALUE);
grid.addView(view3, Sizing.Split, view2, Direction.Down);

const view4 = new TestView(50, Number.MAX_VALUE, 50, Number.MAX_VALUE);
grid.addView(view4, Sizing.Split, view2, Direction.Right);
assert.deepEqual(view1.size, [400, 600]);
assert.deepEqual(view2.size, [200, 300]);
assert.deepEqual(view3.size, [400, 300]);
assert.deepEqual(view4.size, [200, 300]);

grid.removeView(view3);
assert.deepEqual(view1.size, [400, 600]);
assert.deepEqual(view2.size, [200, 600]);
assert.deepEqual(view4.size, [200, 600]);
});
});

class TestSerializableView extends TestView implements ISerializableView {
Expand Down

0 comments on commit d88d83a

Please sign in to comment.