diff --git a/frontend/faraday/lib/layoutState.ts b/frontend/faraday/lib/layoutState.ts index 91ef5f194..c76a7a1b9 100644 --- a/frontend/faraday/lib/layoutState.ts +++ b/frontend/faraday/lib/layoutState.ts @@ -277,11 +277,6 @@ function moveNode(layoutTreeState: LayoutTreeState, 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(layoutTreeState: LayoutTreeState, 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;