( node: RightSidebarLayoutNode, tab: TabType )
| 193 | } |
| 194 | |
| 195 | function removeTabFromNode( |
| 196 | node: RightSidebarLayoutNode, |
| 197 | tab: TabType |
| 198 | ): RightSidebarLayoutNode | null { |
| 199 | if (node.type === "tabset") { |
| 200 | const oldIndex = node.tabs.indexOf(tab); |
| 201 | const tabs = node.tabs.filter((t) => t !== tab); |
| 202 | if (tabs.length === 0) return null; |
| 203 | |
| 204 | let activeTab = node.activeTab; |
| 205 | if (node.activeTab === tab) { |
| 206 | activeTab = tabs[Math.min(oldIndex, tabs.length - 1)]; |
| 207 | } |
| 208 | return { |
| 209 | ...node, |
| 210 | tabs, |
| 211 | activeTab: tabs.includes(activeTab) ? activeTab : tabs[0], |
| 212 | }; |
| 213 | } |
| 214 | |
| 215 | const left = removeTabFromNode(node.children[0], tab); |
| 216 | const right = removeTabFromNode(node.children[1], tab); |
| 217 | |
| 218 | if (!left && !right) { |
| 219 | return null; |
| 220 | } |
| 221 | |
| 222 | // If one side goes empty, promote the other side to avoid empty panes. |
| 223 | if (!left) return right; |
| 224 | if (!right) return left; |
| 225 | |
| 226 | return { |
| 227 | ...node, |
| 228 | children: [left, right], |
| 229 | }; |
| 230 | } |
| 231 | |
| 232 | export function removeTabEverywhere( |
| 233 | state: RightSidebarLayoutState, |
no outgoing calls
no test coverage detected