Skip to content

Commit e618729

Browse files
Fixing missing case for handling root node for splitting, fixes micro-editor#3980
1 parent 6a62575 commit e618729

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

internal/views/splits.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func (n *Node) HSplit(bottom bool) uint64 {
413413
if !n.IsLeaf() {
414414
return 0
415415
}
416-
if n.Kind == STUndef {
416+
if n.parent == nil {
417417
n.Kind = STVert
418418
}
419419
if n.Kind == STVert {
@@ -429,13 +429,13 @@ func (n *Node) VSplit(right bool) uint64 {
429429
if !n.IsLeaf() {
430430
return 0
431431
}
432-
if n.Kind == STUndef {
432+
if n.parent == nil {
433433
n.Kind = STHoriz
434434
}
435-
if n.Kind == STVert {
436-
return n.vVSplit(right)
435+
if n.Kind == STHoriz {
436+
return n.hVSplit(0, right)
437437
}
438-
return n.hVSplit(0, right)
438+
return n.vVSplit(right)
439439
}
440440

441441
// unsplits the child of a split
@@ -531,11 +531,19 @@ func (n *Node) flatten() {
531531
func (n *Node) String() string {
532532
var strf func(n *Node, ident int) string
533533
strf = func(n *Node, ident int) string {
534-
marker := "|"
535-
if n.Kind == STHoriz {
536-
marker = "-"
534+
var marker string
535+
var parentId uint64 = 0
536+
if n.parent == nil {
537+
marker = "/"
538+
} else {
539+
if n.Kind == STHoriz {
540+
marker = "-"
541+
} else if n.Kind == STVert {
542+
marker = "|"
543+
}
544+
parentId = n.parent.id
537545
}
538-
str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id)
546+
str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id, parentId)
539547
if n.IsLeaf() {
540548
str += "🍁"
541549
}

0 commit comments

Comments
 (0)