mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
Fix order of operations when moving nodes (#40)
Insert the node at the new location before removing it from its old location. With the old order, removing a node from its parent could change the indexing of the parent node, if moving a node to a new location under the same parent.
This commit is contained in:
parent
cff7a54507
commit
9809414eb0
@ -277,11 +277,6 @@ function moveNode<T>(layoutTreeState: LayoutTreeState<T>, action: LayoutTreeMove
|
||||
|
||||
console.log(node, parent, oldParent);
|
||||
|
||||
// Remove nodeToInsert from its old parent
|
||||
if (oldParent) {
|
||||
removeChild(oldParent, node);
|
||||
}
|
||||
|
||||
if (!parent && action.insertAtRoot) {
|
||||
if (!rootNode.children) {
|
||||
addIntermediateNode(rootNode);
|
||||
@ -292,6 +287,12 @@ function moveNode<T>(layoutTreeState: LayoutTreeState<T>, action: LayoutTreeMove
|
||||
} else {
|
||||
throw new Error("Invalid InsertOperation");
|
||||
}
|
||||
|
||||
// Remove nodeToInsert from its old parent
|
||||
if (oldParent) {
|
||||
removeChild(oldParent, node);
|
||||
}
|
||||
|
||||
const { node: newRootNode, leafs } = balanceNode(layoutTreeState.rootNode);
|
||||
layoutTreeState.rootNode = newRootNode;
|
||||
layoutTreeState.leafs = leafs;
|
||||
|
Loading…
Reference in New Issue
Block a user