MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / insertNodeAtIndex

Function insertNodeAtIndex

frontend/layout/lib/layoutTree.ts:299–321  ·  view source on GitHub ↗
(layoutState: LayoutTreeState, action: LayoutTreeInsertNodeAtIndexAction)

Source from the content-addressed store, hash-verified

297}
298
299export 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
323export function swapNode(layoutState: LayoutTreeState, action: LayoutTreeSwapNodeAction) {
324 if (!action.node1Id || !action.node2Id) {

Callers 1

treeReducerMethod · 0.90

Calls 2

addChildAtFunction · 0.90

Tested by

no test coverage detected