Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions internal/views/splits.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (n *Node) HSplit(bottom bool) uint64 {
if !n.IsLeaf() {
return 0
}
if n.Kind == STUndef {
if n.parent == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next commit seems to make this change unneeded? I mean, if we guarantee that the root is always STUndef, why not use it? Otherwise, if we don't use STUndef, why do we even need it?

And IMHO using STUndef makes the code a bit more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing but I would think n.parent == nil is more straightforward no? Since that is the definition of root node.

A child node can be of type STUndef (Although it is a bug), but a child node definite cannot have a node parent of nil right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, again, why need this STUndef constant at all?

Although, after more thought, - ok, let's keep it (even though it is causing a bit of redundancy), just to let it reflect that it is indeed undefined whether it is horizontal or vertical.

Copy link
Contributor Author

@Neko-Box-Coder Neko-Box-Coder Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, again, why need this STUndef constant at all?

Nah, we don't need it. Didn't do it cuz I only did minimal change just to fix the issue.

It doesn't matter if it is horizontal or not if it gets changed anyway. If we agree to remove it, I can do it :)

n.Kind = STVert
}
if n.Kind == STVert {
Expand All @@ -429,13 +429,13 @@ func (n *Node) VSplit(right bool) uint64 {
if !n.IsLeaf() {
return 0
}
if n.Kind == STUndef {
if n.parent == nil {
n.Kind = STHoriz
}
if n.Kind == STVert {
return n.vVSplit(right)
if n.Kind == STHoriz {
return n.hVSplit(0, right)
}
return n.hVSplit(0, right)
return n.vVSplit(right)
}

// unsplits the child of a split
Expand Down Expand Up @@ -483,7 +483,14 @@ func (n *Node) Unsplit() bool {
// flattens the tree by removing unnecessary intermediate parents that have only one child
// and handles the side effect of it
func (n *Node) flatten() {
if n.parent == nil || len(n.children) != 1 {
if len(n.children) != 1 {
return
}

// Special case for root node
if n.parent == nil {
*n = *n.children[0]
n.parent = nil
return
}

Expand Down Expand Up @@ -531,11 +538,17 @@ func (n *Node) flatten() {
func (n *Node) String() string {
var strf func(n *Node, ident int) string
strf = func(n *Node, ident int) string {
marker := "|"
marker := "/"
if n.Kind == STHoriz {
marker = "-"
} else if n.Kind == STVert {
marker = "|"
}
var parentId uint64 = 0
if n.parent != nil {
parentId = n.parent.id
}
str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id)
str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id, parentId)
if n.IsLeaf() {
str += "🍁"
}
Expand Down