Fix unable to perform proportional resize caused by chained parents after quiting a nested VSplit inside a HSplit#3708
Conversation
1bd50d1 to
ec4ca05
Compare
|
Nice fix, thanks. |
b31dc40 to
dadb96b
Compare
b68dda9 to
14191dc
Compare
14191dc to
6bc55d3
Compare
5f35974 to
025e822
Compare
internal/views/splits.go
Outdated
| successor.parent = n.parent | ||
| if successor.IsLeaf() { | ||
| successor.Kind = n.Kind | ||
| } else if !successor.IsLeaf() && successor.Kind == n.parent.Kind { |
There was a problem hiding this comment.
!successor.IsLeaf() here is redundant?
And actually successor.Kind == n.parent.Kind seems redundant too, it should always be true, unless we have a bug?
internal/views/splits.go
Outdated
| successor.Kind = n.Kind | ||
| } else if !successor.IsLeaf() && successor.Kind == n.parent.Kind { | ||
| // If we have the same kind as the parent (caused by removing chained parent), | ||
| // replace successor node with its children. |
There was a problem hiding this comment.
If we remove successor.Kind == n.parent.Kind above as redundant, we can update this comment like: "If the successor node has its own children, it means it is a redundant chained parent too, so replace it with its children."?
There was a problem hiding this comment.
Yeah, that is true. I wasn't thinking much when copying and pasting this part.
internal/views/splits.go
Outdated
| } | ||
|
|
||
| // Update propW and propH since the parent of the children might have been updated, | ||
| // so the children may have new siblings |
There was a problem hiding this comment.
s/might have been updated/has been updated/
s/may have new siblings/have new siblings/
?
internal/views/splits.go
Outdated
| // Replace current node with its child node to remove chained parent | ||
| n.parent.children[ind] = n.children[0] | ||
|
|
||
| successor := n.parent.children[ind] |
There was a problem hiding this comment.
Maybe add a comment above this line: "Make sure the tree remains in a consistent state: any child node's kind (horizontal vs vertical) is the opposite of its parent's kind"?
Also why not rearrange the lines like this:
--- a/internal/views/splits.go
+++ b/internal/views/splits.go
@@ -495,10 +495,12 @@ func (n *Node) flatten() {
}
// Replace current node with its child node to remove chained parent
- n.parent.children[ind] = n.children[0]
-
- successor := n.parent.children[ind]
+ successor := n.children[0]
+ n.parent.children[ind] = successor
successor.parent = n.parent
+
+ // Maintain the tree in a consistent state: any child node's kind (horiz vs vert)
+ // should be the opposite of its parent's kind.
if successor.IsLeaf() {
successor.Kind = n.Kind
} else if !successor.IsLeaf() && successor.Kind == n.parent.Kind {025e822 to
8e70899
Compare
When you do a HSplit, follow by a VSplit, then quit the last pane and do a HSplit again, the proportional resize won't work as expected.
Currently you will get a 50%, 25%, 25% HSplits.
Instead it should be 33%, 33%, 33%.
This problem is caused by failing to resolve chained parents and the resize is called on the "wrong" parent.
The patch fixes chained parents by simplifying the tree when unsplittng.
This problem can be visualized by calling the
String()on the current tab. In lua, it will look something like this:So if you have something like this
the tree looks like this:
If you quit the 3rd pane, the tree will look like this:
Then if you do a VSplit, the tree will look like
Which fails the resize since it is calling on a chained parent
After applying the patch, it will "simplify" the tree after quitting the 3rd pane
Then when you do another VSplit, it will look like this:
and the resize will work as expected since it will be called on the correct parent.