Skip to content

Commit 22adeef

Browse files
Adding special case for root node for flatten()
1 parent e618729 commit 22adeef

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/views/splits.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,17 @@ func (n *Node) Unsplit() bool {
483483
// flattens the tree by removing unnecessary intermediate parents that have only one child
484484
// and handles the side effect of it
485485
func (n *Node) flatten() {
486-
if n.parent == nil || len(n.children) != 1 {
486+
if len(n.children) != 1 {
487+
return
488+
}
489+
490+
// Special case for root node
491+
if n.parent == nil {
492+
*n = *n.children[0]
493+
n.parent = nil
494+
for _, c := range n.children {
495+
c.parent = n
496+
}
487497
return
488498
}
489499

0 commit comments

Comments
 (0)