(layoutState: LayoutTreeState, action: LayoutTreeInsertNodeAtIndexAction)
| 297 | } |
| 298 | |
| 299 | export function insertNodeAtIndex(layoutState: LayoutTreeState, action: LayoutTreeInsertNodeAtIndexAction) { |
| 300 | if (!action?.node || !action?.indexArr) { |
| 301 | console.error("insertNodeAtIndex cannot run, either node or indexArr field is missing"); |
| 302 | return; |
| 303 | } |
| 304 | if (!layoutState.rootNode) { |
| 305 | layoutState.rootNode = action.node; |
| 306 | } else { |
| 307 | const insertLoc = findInsertLocationFromIndexArr(layoutState.rootNode, action.indexArr); |
| 308 | if (!insertLoc) { |
| 309 | console.error("insertNodeAtIndex unable to find insert location"); |
| 310 | return; |
| 311 | } |
| 312 | addChildAt(insertLoc.node, insertLoc.index + 1, action.node); |
| 313 | if (action.magnified) { |
| 314 | layoutState.magnifiedNodeId = action.node.id; |
| 315 | layoutState.focusedNodeId = action.node.id; |
| 316 | } |
| 317 | } |
| 318 | if (action.focused) { |
| 319 | layoutState.focusedNodeId = action.node.id; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | export function swapNode(layoutState: LayoutTreeState, action: LayoutTreeSwapNodeAction) { |
| 324 | if (!action.node1Id || !action.node2Id) { |
no test coverage detected