Skip to content

Commit fda43af

Browse files
Adding special case for root node for flatten()
1 parent 7ef8ca4 commit fda43af

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/views/splits.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,20 @@ 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+
}
497+
if len(n.children) == 0 {
498+
n.Kind = STUndef
499+
}
487500
return
488501
}
489502

0 commit comments

Comments
 (0)