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
32 changes: 24 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,17 @@ 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
Comment on lines +492 to +493
Copy link
Member

@JoeKar JoeKar Feb 2, 2026

Choose a reason for hiding this comment

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

Ah, yes...right. We overwrite the root node with the last remaining children, by which it receives the id of the children, with which it is identified in the tab resize.
But still we should keep the removed n.Kind = STUndef, otherwise func (n *Node) String() wouldn't print what we expect from the new root. Otherwise in case we agree to remove STUndef we've to adjust this function to print "/" on n.parent == nil.

Am I right that we should keep the fault in tab.go#L382 to identify that something went wrong, because GetNode() returns nil by intention in case the pane ID wasn't found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise in case we agree to remove STUndef we've to adjust this function to print "/" on n.parent == nil.

True. Forgot about that change when I made this change. Will add it back if we want to leave STUndef as it is.

Am I right that we should keep the fault in tab.go#L382 to identify that something went wrong, because GetNode() returns nil by intention in case the pane ID wasn't found?

Not sure what fault you are referring to. t.GetNode(p.ID()) should never fail no?

Copy link
Member

@JoeKar JoeKar Feb 2, 2026

Choose a reason for hiding this comment

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

Not sure what fault you are referring to. t.GetNode(p.ID()) should never fail no?

But it can splits.go#L140 and this is intended, when the given ID isn't present at the related nodes.

Will add it back if we want to leave STUndef as it is.

I vote for keeping it too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I am missing something but the given id should always be present for the node unless something is wrong no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I vote for keeping it too.

I vote for removing it :) since it's sole purpose is to identify root node and that can be done by just checking if parent exists or not.

Just need @dmaluka 's vote or anyone else interested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I vote for keeping it, so that we don't need to meaninglessly pass STVert or STHoriz to NewNode() when creating the root node.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay got it. Added back the n.Kind = STUndef

for _, c := range n.children {
c.parent = n
}
return
}

Expand Down Expand Up @@ -531,11 +541,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