Skip to content

Commit

Permalink
grid: resize views when branch is demoted
Browse files Browse the repository at this point in the history
fixes #50675
  • Loading branch information
joaomoreno committed May 30, 2018
1 parent 4d3174d commit e84e16c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/vs/base/browser/ui/grid/gridview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

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 @@ -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 {
Expand Down

0 comments on commit e84e16c

Please sign in to comment.