MCPcopy
hub / github.com/coder/mux / closeSplit

Function closeSplit

src/browser/utils/rightSidebarLayout.ts:808–842  ·  view source on GitHub ↗
(
  state: RightSidebarLayoutState,
  splitId: string,
  keepChildIndex: 0 | 1
)

Source from the content-addressed store, hash-verified

806 * @param keepChildIndex Which child to keep (0 = first/left/top, 1 = second/right/bottom)
807 */
808export function closeSplit(
809 state: RightSidebarLayoutState,
810 splitId: string,
811 keepChildIndex: 0 | 1
812): RightSidebarLayoutState {
813 const replaceNode = (node: RightSidebarLayoutNode): RightSidebarLayoutNode => {
814 if (node.type === "tabset") {
815 return node;
816 }
817
818 if (node.id === splitId) {
819 // Replace this split with the kept child
820 return node.children[keepChildIndex];
821 }
822
823 return {
824 ...node,
825 children: [replaceNode(node.children[0]), replaceNode(node.children[1])],
826 };
827 };
828
829 const newRoot = replaceNode(state.root);
830
831 // Ensure focusedTabsetId is still valid
832 let newFocusedId: string = state.focusedTabsetId;
833 if (findTabset(newRoot, newFocusedId) === null) {
834 newFocusedId = findFirstTabsetId(newRoot) ?? state.focusedTabsetId;
835 }
836
837 return {
838 ...state,
839 focusedTabsetId: newFocusedId,
840 root: newRoot,
841 };
842}

Callers 1

Calls 3

replaceNodeFunction · 0.85
findFirstTabsetIdFunction · 0.85
findTabsetFunction · 0.70

Tested by

no test coverage detected