Browse Source

Fixes tree compaction for branches

main
Eric Amodio 5 years ago
parent
commit
7797103321
4 changed files with 25 additions and 9 deletions
  1. +11
    -5
      src/system/array.ts
  2. +4
    -2
      src/views/nodes/branchNode.ts
  3. +5
    -1
      src/views/nodes/branchesNode.ts
  4. +5
    -1
      src/views/nodes/remoteNode.ts

+ 11
- 5
src/system/array.ts View File

@ -94,7 +94,8 @@ export namespace Arrays {
values: T[], values: T[],
splitPath: (i: T) => string[], splitPath: (i: T) => string[],
joinPath: (...paths: string[]) => string, joinPath: (...paths: string[]) => string,
compact: boolean = false
compact: boolean = false,
canCompact?: (i: T) => boolean
): HierarchicalItem<T> { ): HierarchicalItem<T> {
const seed = { const seed = {
name: '', name: '',
@ -139,7 +140,7 @@ export namespace Arrays {
}, seed); }, seed);
if (compact) { if (compact) {
hierarchy = compactHierarchy(hierarchy, joinPath, true);
hierarchy = compactHierarchy(hierarchy, joinPath, true, canCompact);
} }
return hierarchy; return hierarchy;
@ -148,22 +149,27 @@ export namespace Arrays {
export function compactHierarchy<T>( export function compactHierarchy<T>(
root: HierarchicalItem<T>, root: HierarchicalItem<T>,
joinPath: (...paths: string[]) => string, joinPath: (...paths: string[]) => string,
isRoot: boolean = true
isRoot: boolean = true,
canCompact?: (i: T) => boolean
): HierarchicalItem<T> { ): HierarchicalItem<T> {
if (root.children === undefined) return root; if (root.children === undefined) return root;
const children = [...root.children.values()]; const children = [...root.children.values()];
for (const child of children) { for (const child of children) {
compactHierarchy(child, joinPath, false);
compactHierarchy(child, joinPath, false, canCompact);
} }
if (!isRoot && children.length === 1) { if (!isRoot && children.length === 1) {
const child = children[0]; const child = children[0];
if (child.value === undefined) {
if (
root.value === undefined &&
(child.value === undefined || canCompact === undefined || canCompact(child.value))
) {
root.name = joinPath(root.name, child.name); root.name = joinPath(root.name, child.name);
root.relativePath = child.relativePath; root.relativePath = child.relativePath;
root.children = child.children; root.children = child.children;
root.descendants = child.descendants; root.descendants = child.descendants;
root.value = child.value;
} }
} }

+ 4
- 2
src/views/nodes/branchNode.ts View File

@ -40,6 +40,8 @@ export class BranchNode extends ViewRefNode implements Pageabl
return BranchNode.getId(this.branch.repoPath, this.branch.name, this.root); return BranchNode.getId(this.branch.repoPath, this.branch.name, this.root);
} }
compacted: boolean = false;
get current(): boolean { get current(): boolean {
return this.branch.current; return this.branch.current;
} }
@ -48,7 +50,7 @@ export class BranchNode extends ViewRefNode implements Pageabl
const branchName = this.branch.getName(); const branchName = this.branch.getName();
if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchName; if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchName;
return (this.root && this.current) || this.branch.detached || this.branch.starred
return this.compacted || this.root || this.current || this.branch.detached || this.branch.starred
? branchName ? branchName
: this.branch.getBasename(); : this.branch.getBasename();
} }
@ -58,7 +60,7 @@ export class BranchNode extends ViewRefNode implements Pageabl
} }
get treeHierarchy(): string[] { get treeHierarchy(): string[] {
return this.branch.current || this.branch.detached || this.branch.starred
return this.rootan> class="o">|| this.current || this.branch.detached || this.branch.starred
? [this.branch.name] ? [this.branch.name]
: this.branch.getName().split('/'); : this.branch.getName().split('/');
} }

+ 5
- 1
src/views/nodes/branchesNode.ts View File

@ -43,7 +43,11 @@ export class BranchesNode extends ViewNode {
branchNodes, branchNodes,
n => n.treeHierarchy, n => n.treeHierarchy,
(...paths) => paths.join('/'), (...paths) => paths.join('/'),
this.view.config.files.compact
this.view.config.files.compact,
b => {
b.compacted = true;
return true;
}
); );
const root = new BranchOrTagFolderNode( const root = new BranchOrTagFolderNode(

+ 5
- 1
src/views/nodes/remoteNode.ts View File

@ -51,7 +51,11 @@ export class RemoteNode extends ViewNode {
branchNodes, branchNodes,
n => n.treeHierarchy, n => n.treeHierarchy,
(...paths) => paths.join('/'), (...paths) => paths.join('/'),
this.view.config.files.compact
this.view.config.files.compact,
b => {
b.compacted = true;
return true;
}
); );
const root = new BranchOrTagFolderNode( const root = new BranchOrTagFolderNode(

Loading…
Cancel
Save