Check collapse state of tree node when doing recursive refresh (#127071)

* Check collapse state of tree node when doing recursive refresh
Fixes #127035

* test case for #127071

Co-authored-by: João Moreno <joao.moreno@microsoft.com>
This commit is contained in:
Alex Ross 2021-06-28 16:12:05 +02:00 committed by GitHub
parent 309e424da1
commit c683180c66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View file

@ -881,6 +881,10 @@ export class AsyncDataTree<TInput, T, TFilterData = void> implements IDisposable
asyncDataTreeNode.children.forEach(node => dfs(node, node => this.nodes.delete(node.element as T)));
asyncDataTreeNode.children.splice(0, asyncDataTreeNode.children.length);
asyncDataTreeNode.stale = true;
if (this.collapseByDefault && !this.collapseByDefault(element)) {
asyncDataTreeNode.collapsedByDefault = false;
childrenToRefresh.push(asyncDataTreeNode);
}
} else {
childrenToRefresh.push(asyncDataTreeNode);
}

View file

@ -435,4 +435,45 @@ suite('AsyncDataTree', function () {
assert.deepStrictEqual(Array.from(container.querySelectorAll('.monaco-list-row')).map(e => e.textContent), ['a', 'b2']);
});
test('issue #127035 - tree should react to collapseByDefault toggles', async () => {
const container = document.createElement('div');
const model = new Model({
id: 'root',
children: [{
id: 'a'
}]
});
let collapseByDefault = () => true;
const tree = new AsyncDataTree<Element, Element>('test', container, new VirtualDelegate(), [new Renderer()], new DataSource(), {
identityProvider: new IdentityProvider(),
collapseByDefault: _ => collapseByDefault()
});
tree.layout(200);
await tree.setInput(model.root);
assert.strictEqual(container.querySelectorAll('.monaco-list-row').length, 1);
let twistie = container.querySelector('.monaco-list-row:first-child .monaco-tl-twistie') as HTMLElement;
assert(!twistie.classList.contains('collapsible'));
assert(!twistie.classList.contains('collapsed'));
collapseByDefault = () => false;
model.get('a').children = [{ id: 'aa' }];
await tree.updateChildren(model.root, true);
const rows = container.querySelectorAll('.monaco-list-row');
assert.strictEqual(rows.length, 2);
const aTwistie = rows.item(0).querySelector('.monaco-tl-twistie') as HTMLElement;
assert(aTwistie.classList.contains('collapsible'));
assert(!aTwistie.classList.contains('collapsed'));
const aaTwistie = rows.item(1).querySelector('.monaco-tl-twistie') as HTMLElement;
assert(!aaTwistie.classList.contains('collapsible'));
assert(!aaTwistie.classList.contains('collapsed'));
tree.dispose();
});
});