fix: inserting orthogonal gridview when empty should not add new views

This commit is contained in:
mathuo 2023-07-05 20:22:57 +01:00
parent 1462b6a37a
commit 47fb99a06f
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
2 changed files with 36 additions and 0 deletions

View File

@ -690,4 +690,37 @@ describe('gridview', () => {
gridview.element.querySelectorAll('.mock-grid-view').length
).toBe(4);
});
test('that calling insertOrthogonalSplitviewAtRoot() for an empty view doesnt add any nodes', () => {
const gridview = new Gridview(
false,
{ separatorBorder: '' },
Orientation.HORIZONTAL
);
gridview.layout(1000, 1000);
expect(gridview.serialize()).toEqual({
height: 1000,
orientation: 'HORIZONTAL',
root: {
data: [],
size: 1000,
type: 'branch',
},
width: 1000,
});
gridview.insertOrthogonalSplitviewAtRoot();
expect(gridview.serialize()).toEqual({
height: 1000,
orientation: 'VERTICAL',
root: {
data: [],
size: 1000,
type: 'branch',
},
width: 1000,
});
});
});

View File

@ -455,6 +455,9 @@ export class Gridview implements IDisposable {
this.root.size
);
if (oldRoot.children.length === 0) {
// no data so no need to add anything back in
} else
if (oldRoot.children.length === 1) {
// can remove one level of redundant branching if there is only a single child
const childReference = oldRoot.children[0];