mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-25 04:36:23 +00:00
tree: collapse all
This commit is contained in:
@@ -170,6 +170,9 @@ export class Tree<T> implements IDisposable {
|
||||
onKeyDown.filter(e => e.keyCode === KeyCode.LeftArrow).on(this.onLeftArrow, this, this.disposables);
|
||||
onKeyDown.filter(e => e.keyCode === KeyCode.RightArrow).on(this.onRightArrow, this, this.disposables);
|
||||
onKeyDown.filter(e => e.keyCode === KeyCode.Space).on(this.onSpace, this, this.disposables);
|
||||
|
||||
// TODO@joao cleanup
|
||||
onKeyDown.filter(e => e.keyCode === KeyCode.KEY_A).on(() => this.model.setCollapsedAll(true), null, this.disposables);
|
||||
}
|
||||
|
||||
splice(location: number[], deleteCount: number, toInsert: ISequence<ITreeElement<T>> = Iterator.empty()): Iterator<ITreeElement<T>> {
|
||||
|
||||
@@ -166,16 +166,16 @@ export class TreeModel<T> {
|
||||
}
|
||||
|
||||
setCollapsed(location: number[], collapsed: boolean): boolean {
|
||||
return this._setCollapsed(location, collapsed);
|
||||
const { node, listIndex, visible } = this.findNode(location);
|
||||
return this._setCollapsed(node, listIndex, visible, collapsed);
|
||||
}
|
||||
|
||||
toggleCollapsed(location: number[]): void {
|
||||
this._setCollapsed(location);
|
||||
const { node, listIndex, visible } = this.findNode(location);
|
||||
this._setCollapsed(node, listIndex, visible);
|
||||
}
|
||||
|
||||
private _setCollapsed(location: number[], collapsed?: boolean | undefined): boolean {
|
||||
const { node, listIndex, visible } = this.findNode(location);
|
||||
|
||||
private _setCollapsed(node: IMutableTreeNode<T>, listIndex: number, visible: boolean, collapsed?: boolean | undefined): boolean {
|
||||
if (!node.collapsible) {
|
||||
return false;
|
||||
}
|
||||
@@ -195,13 +195,29 @@ export class TreeModel<T> {
|
||||
const toInsert = updateVisibleCount(node);
|
||||
|
||||
this.list.splice(listIndex + 1, previousVisibleCount - 1, toInsert.slice(1));
|
||||
this._onDidChangeCollapseState.fire(node);
|
||||
}
|
||||
|
||||
this._onDidChangeCollapseState.fire(node);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO@joao cleanup
|
||||
setCollapsedAll(collapsed: boolean): void {
|
||||
if (collapsed) {
|
||||
const queue = [...this.root.children]; // TODO@joao use a linked list
|
||||
let listIndex = 0;
|
||||
|
||||
while (queue.length > 0) {
|
||||
const node = queue.shift();
|
||||
const visible = listIndex < this.root.children.length;
|
||||
this._setCollapsed(node, listIndex, visible, collapsed);
|
||||
|
||||
queue.push(...node.children);
|
||||
listIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isCollapsed(location: number[]): boolean {
|
||||
return this.findNode(location).node.collapsed;
|
||||
}
|
||||
|
||||
@@ -44,21 +44,40 @@
|
||||
|
||||
const tree = new Tree(container, delegate, [renderer]);
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/api/ls?path=');
|
||||
xhr.send();
|
||||
xhr.onreadystatechange = function () {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
const data = JSON.parse(this.responseText);
|
||||
function setModel(model) {
|
||||
performance.mark('before splice');
|
||||
const start = performance.now();
|
||||
tree.splice([0], 0, model);
|
||||
console.log('splice took', performance.now() - start);
|
||||
performance.mark('after splice');
|
||||
}
|
||||
|
||||
performance.mark('before splice');
|
||||
const start = performance.now();
|
||||
tree.splice([0], 0, [data]);
|
||||
console.log('splice took', performance.now() - start);
|
||||
performance.mark('after splice');
|
||||
switch (location.search) {
|
||||
case '?problems': {
|
||||
const files = [];
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
const errors = [];
|
||||
|
||||
for (let j = 1; j <= (i % 5) + 1; j++) {
|
||||
errors.push({ element: `error #${j}` });
|
||||
}
|
||||
|
||||
files.push({ element: `file #${i}`, children: errors });
|
||||
}
|
||||
setModel(files);
|
||||
break;
|
||||
}
|
||||
};
|
||||
default:
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/api/ls?path=');
|
||||
xhr.send();
|
||||
xhr.onreadystatechange = function () {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
setModel([JSON.parse(this.responseText)]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user