未验证 提交 a8dd7f60 编写于 作者: C Connor Peet

update collapsible when children change

上级 9b83eb6e
......@@ -228,6 +228,7 @@ export class IndexTreeModel<T extends Exclude<any, undefined>, TFilterData = voi
const nodesToInsertIterator = Iterable.map(toInsert, el => this.createTreeNode(el, parentNode, parentNode.visible ? TreeVisibility.Visible : TreeVisibility.Hidden, revealed, treeListElementsToInsert, onDidCreateNode));
const lastIndex = location[location.length - 1];
const lastHadChildren = parentNode.children.length > 0;
// figure out what's the visible child start index right before the
// splice point
......@@ -296,6 +297,11 @@ export class IndexTreeModel<T extends Exclude<any, undefined>, TFilterData = voi
deletedNodes.forEach(visit);
}
const currentlyHasChildren = parentNode.children.length > 0;
if (lastHadChildren !== currentlyHasChildren) {
this.setCollapsible(location.slice(0, -1), currentlyHasChildren);
}
this._onDidSplice.fire({ insertedNodes: nodesToInsert, deletedNodes });
let node: IIndexTreeNode<T, TFilterData> | undefined = parentNode;
......
......@@ -309,6 +309,30 @@ suite('IndexTreeModel', () => {
assert.deepEqual(list[2].depth, 1);
}));
test('updates collapsible', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
model.splice([0], 0, [
{
element: 0, children: [
{ element: 1 },
]
},
], options);
assert.strictEqual(list[0].collapsible, true);
assert.strictEqual(list[1].collapsible, false);
model.splice([0, 0], 1, [], options);
assert.strictEqual(list[0].collapsible, false);
assert.strictEqual(list[1], undefined);
model.splice([0, 0], 0, [{ element: 1 }], options);
assert.strictEqual(list[0].collapsible, true);
assert.strictEqual(list[1].collapsible, false);
}));
test('expand', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册