-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fixing missing case for handling root node for splitting #3983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fixing missing case for handling root node for splitting #3983
Conversation
|
When this is the initial state... ...and this the state after the first unsplit (back to just one pane)... ...shouldn't we flat this state into the initial state already to return to the initial state with this one and last split? So that any further unsplit doesn't do anything, even not in the background. Besides of that the rearrangement of |
I did think about this while creating the PR fix. The thing is I think this behavior has always been a valid state for the root node, whether it is before or after my One of the trick point is that the I probably could change the logic of I vaguely remember the first iteration of So in short, in theory yes I agree with you. In practice I will probably need to spend more time to recover my memory on how it works and see if I can modify it without making it recursive. And also need to test it as well. I can take a look at it at some point but can't promise anything for now. If you want to have a try, go for it :) |
c8a121f to
a87f3dd
Compare
func (n *Node) flatten() {
if len(n.children) != 1 {
return
}
if n.parent == nil {
n.Kind = STUndef
n.children = n.children[:0]
return
}
[...]Not 100% sure, if this covers all and everything, but looks good from behavior and node printing. |
| return 0 | ||
| } | ||
| if n.Kind == STUndef { | ||
| if n.parent == nil { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
Just tried testing this PR... Apparently it is fixing one crash but introducing another one, which is even easier to reproduce: for example:
Result: |
At the beginning, the node tree looks like this, where x =
STUndefWhen performing VSplit or HSplit at the beginning, we check if we are root node using
STUndef, in which we will always put the new split as its children, then we set the node kind for the root node. Which then looks like this:Since we have set root node kind after the initial split, the special handling for the root node using
STUndefwill no longer be valid.When using quit instead of unsplit, you can only get to the following node tree, and doing quit on the child will quit micro entirely.
However, if you are using unsplit, you can actually go back to the original state, like this:
One pane left:
After unsplit:
The fix is simply check if the parent is
nilto determine if we are the root node or not.I have also rearrange
VSplitlast if condition to matchHSplitwhere we are treating current node as non-leaf node and add the new split to it's children.Also updated the
String()to show the parent node id for easier debugging.Fixes #3980