Skip to content

Commit

Permalink
Adds root path collapsing with compact hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed May 2, 2019
1 parent d2b87f9 commit 1a66dd6
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/system/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export namespace Arrays {
relativePath: string;
value?: T;

// parent?: HierarchicalItem<T>;
parent?: HierarchicalItem<T>;
children: Map<string, HierarchicalItem<T>> | undefined;
descendants: T[] | undefined;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ export namespace Arrays {
f = {
name: folderName,
relativePath: relativePath,
// parent: folder,
parent: folder,
children: undefined,
descendants: undefined
};
Expand Down Expand Up @@ -149,18 +149,20 @@ export namespace Arrays {

const children = [...root.children.values()];

// // Attempts less nesting but duplicate roots
// if (!isRoot && children.every(c => c.value === undefined)) {
// const parentSiblings = root.parent!.children!;
// if (parentSiblings[root.name] !== undefined) {
// delete parentSiblings[root.name];

// for (const child of children) {
// child.name = joinPath(root.name, child.name);
// parentSiblings[child.name] = child;
// }
// }
// }
// Less nesting but duplicate roots
if (!isRoot && children.every(c => c.value === undefined)) {
const siblings = root.parent && root.parent.children;
if (siblings !== undefined) {
if (siblings.get(root.name) !== undefined) {
siblings.delete(root.name);

for (const child of children) {
child.name = joinPath(root.name, child.name);
siblings.set(child.name, child);
}
}
}
}

for (const child of children) {
compactHierarchy(child, joinPath, false);
Expand Down

0 comments on commit 1a66dd6

Please sign in to comment.