MCPcopy
hub / github.com/wavetermdev/waveterm / genericClose

Function genericClose

frontend/app/store/keymodel.ts:182–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

180}
181
182function 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
231function switchBlockByBlockNum(index: number) {
232 const layoutModel = getLayoutModelForStaticTab();

Callers 1

registerGlobalKeysFunction · 0.85

Calls 12

replaceBlockFunction · 0.90
fireAndForgetFunction · 0.90
getStaticTabBlockCountFunction · 0.85
simpleCloseStaticTabFunction · 0.85
setAIPanelVisibleMethod · 0.80
getAIPanelVisibleMethod · 0.80
getMethod · 0.80
hasNonEmptyInputMethod · 0.80
focusInputMethod · 0.80
getFocusTypeMethod · 0.45
getInstanceMethod · 0.45

Tested by

no test coverage detected