Skip to content

Commit c554fa7

Browse files
Adding special case for root node for flatten()
1 parent a87f3dd commit c554fa7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

internal/views/splits.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,14 @@ 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
487494
return
488495
}
489496

0 commit comments

Comments
 (0)