MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / splitVertical

Function splitVertical

frontend/layout/lib/layoutTree.ts:497–534  ·  view source on GitHub ↗
(layoutState: LayoutTreeState, action: LayoutTreeSplitVerticalAction)

Source from the content-addressed store, hash-verified

495// ─── SPLIT VERTICAL ─────────────────────────────────────────────────────────────
496
497export function splitVertical(layoutState: LayoutTreeState, action: LayoutTreeSplitVerticalAction) {
498 const { targetNodeId, newNode, position } = action;
499 const targetNode = findNode(layoutState.rootNode, targetNodeId);
500 if (!targetNode) {
501 console.error("splitVertical: Target node not found", targetNodeId);
502 return;
503 }
504
505 const parent = findParent(layoutState.rootNode, targetNodeId);
506 if (parent && parent.flexDirection === FlexDirection.Column) {
507 const index = parent.children.findIndex((child) => child.id === targetNodeId);
508 if (index === -1) {
509 console.error("splitVertical: Target node not found in parent's children", targetNodeId);
510 return;
511 }
512 const insertIndex = position === "before" ? index : index + 1;
513 // For vertical splits in an already vertical parent, splice directly.
514 parent.children.splice(insertIndex, 0, newNode);
515 } else {
516 // Wrap target node in a new vertical group.
517 // Create group node with an initial children array so that validation passes.
518 const groupNode = newLayoutNode(FlexDirection.Column, targetNode.size, [targetNode], undefined);
519 groupNode.children = position === "before" ? [newNode, targetNode] : [targetNode, newNode];
520 if (parent) {
521 const index = parent.children.findIndex((child) => child.id === targetNodeId);
522 if (index === -1) {
523 console.error("splitVertical (wrap): Target node not found in parent's children", targetNodeId);
524 return;
525 }
526 parent.children[index] = groupNode;
527 } else {
528 layoutState.rootNode = groupNode;
529 }
530 }
531 if (action.focused) {
532 layoutState.focusedNodeId = newNode.id;
533 }
534}

Callers 1

treeReducerMethod · 0.90

Calls 3

findNodeFunction · 0.90
findParentFunction · 0.90
newLayoutNodeFunction · 0.90

Tested by

no test coverage detected