()
| 180 | } |
| 181 | |
| 182 | function genericClose() { |
| 183 | const focusType = FocusManager.getInstance().getFocusType(); |
| 184 | if (focusType === "waveai") { |
| 185 | WorkspaceLayoutModel.getInstance().setAIPanelVisible(false); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | const workspaceLayoutModel = WorkspaceLayoutModel.getInstance(); |
| 190 | const isAIPanelOpen = workspaceLayoutModel.getAIPanelVisible(); |
| 191 | if (isAIPanelOpen && getStaticTabBlockCount() === 1) { |
| 192 | const aiModel = WaveAIModel.getInstance(); |
| 193 | const shouldSwitchToAI = !globalStore.get(aiModel.isChatEmptyAtom) || aiModel.hasNonEmptyInput(); |
| 194 | if (shouldSwitchToAI) { |
| 195 | const layoutModel = getLayoutModelForStaticTab(); |
| 196 | const focusedNode = globalStore.get(layoutModel.focusedNode); |
| 197 | if (focusedNode) { |
| 198 | replaceBlock(focusedNode.data.blockId, { meta: { view: "launcher" } }, false); |
| 199 | setTimeout(() => WaveAIModel.getInstance().focusInput(), 50); |
| 200 | return; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | const blockCount = getStaticTabBlockCount(); |
| 205 | if (blockCount === 0) { |
| 206 | simpleCloseStaticTab(); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | // If this is the last block, closing it will close the tab — route through simpleCloseStaticTab |
| 211 | // so the tab:confirmclose setting is respected. |
| 212 | if (blockCount === 1) { |
| 213 | simpleCloseStaticTab(); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | const layoutModel = getLayoutModelForStaticTab(); |
| 218 | const focusedNode = globalStore.get(layoutModel.focusedNode); |
| 219 | const blockId = focusedNode?.data?.blockId; |
| 220 | const blockAtom = blockId ? WOS.getWaveObjectAtom<Block>(WOS.makeORef("block", blockId)) : null; |
| 221 | const blockData = blockAtom ? globalStore.get(blockAtom) : null; |
| 222 | const isAIFileDiff = blockData?.meta?.view === "aifilediff"; |
| 223 | |
| 224 | fireAndForget(layoutModel.closeFocusedNode.bind(layoutModel)); |
| 225 | |
| 226 | if (isAIFileDiff && isAIPanelOpen) { |
| 227 | setTimeout(() => WaveAIModel.getInstance().focusInput(), 50); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | function switchBlockByBlockNum(index: number) { |
| 232 | const layoutModel = getLayoutModelForStaticTab(); |
no test coverage detected