The code that was updating the active node after removing a layer/group
was not handling all cases correctly.
The fix updates the logic for setting the active node:
1. If the node is a non-empty group and we're keeping the children, then set
the active node to the top node in the group.
2. Otherwise, if the node has a node below it (in the same group), set it to be the active one.
3. Otherwise, if the node has a node above it (in the same group), set it to be the active one.
4. Otherwise, if the parent is not the root group, set the parent to be the active node.
5. Otherwise, clear the active node.
This behaves the same as in Krita.
Pull Request: https://projects.blender.org/blender/blender/pulls/130126