( state: RightSidebarLayoutState, splitId: string, keepChildIndex: 0 | 1 )
| 806 | * @param keepChildIndex Which child to keep (0 = first/left/top, 1 = second/right/bottom) |
| 807 | */ |
| 808 | export 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 | } |
no test coverage detected