Skip to content

Commit e3711ea

Browse files
committed
fix(web): confirm terminal close from the keybinding too
1 parent 724d03b commit e3711ea

3 files changed

Lines changed: 49 additions & 22 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ import {
4646
import { CHAT_LIST_ANCHOR_OFFSET } from "@t3tools/shared/chatList";
4747
import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts";
4848
import { truncate } from "@t3tools/shared/String";
49-
import { nextTerminalId, resolveTerminalSessionLabel } from "@t3tools/shared/terminalLabels";
49+
import {
50+
getTerminalLabel,
51+
nextTerminalId,
52+
resolveTerminalSessionLabel,
53+
} from "@t3tools/shared/terminalLabels";
5054
import { Debouncer } from "@tanstack/react-pacer";
5155
import { useAtomValue } from "@effect/atom-react";
5256
import {
@@ -192,6 +196,7 @@ import {
192196
import { useNowMinute } from "../hooks/useNowMinute";
193197
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
194198
import { resolveAppModelSelectionForInstance } from "../modelSelection";
199+
import { confirmTerminalClose } from "../lib/terminalCloseConfirm";
195200
import { getTerminalFocusOwner } from "../lib/terminalFocus";
196201
import { preventRepeatedTerminalCloseShortcut } from "../lib/terminalCloseShortcut";
197202
import { resolveNewDraftStartFromOrigin } from "../lib/chatThreadActions";
@@ -3453,6 +3458,24 @@ function ChatViewContent(props: ChatViewProps) {
34533458
},
34543459
[activeRightPanelSurface, activeThreadRef, closeTerminalMutation, storeCloseTerminal],
34553460
);
3461+
const requestCloseTerminal = useCallback(
3462+
(terminalId: string) => {
3463+
const label = activeTerminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId);
3464+
void confirmTerminalClose(label).then((confirmed) => {
3465+
if (confirmed) closeTerminal(terminalId);
3466+
});
3467+
},
3468+
[activeTerminalLabelsById, closeTerminal],
3469+
);
3470+
const requestClosePanelTerminal = useCallback(
3471+
(terminalId: string) => {
3472+
const label = activeTerminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId);
3473+
void confirmTerminalClose(label).then((confirmed) => {
3474+
if (confirmed) closePanelTerminal(terminalId);
3475+
});
3476+
},
3477+
[activeTerminalLabelsById, closePanelTerminal],
3478+
);
34563479
const activateRightPanelSurface = useCallback(
34573480
(surface: RightPanelSurface) => {
34583481
if (!activeThreadRef) return;
@@ -4807,11 +4830,11 @@ function ChatViewContent(props: ChatViewProps) {
48074830
event.preventDefault();
48084831
event.stopPropagation();
48094832
if (terminalFocusOwner === "right-panel" && activeRightPanelSurface?.kind === "terminal") {
4810-
closePanelTerminal(activeRightPanelSurface.activeTerminalId);
4833+
requestClosePanelTerminal(activeRightPanelSurface.activeTerminalId);
48114834
return;
48124835
}
48134836
if (!terminalUiState.terminalOpen) return;
4814-
closeTerminal(terminalUiState.activeTerminalId);
4837+
requestCloseTerminal(terminalUiState.activeTerminalId);
48154838
return;
48164839
}
48174840

@@ -4860,8 +4883,8 @@ function ChatViewContent(props: ChatViewProps) {
48604883
terminalUiState.terminalOpen,
48614884
terminalUiState.activeTerminalId,
48624885
activeThreadId,
4863-
closeTerminal,
4864-
closePanelTerminal,
4886+
requestCloseTerminal,
4887+
requestClosePanelTerminal,
48654888
createNewTerminal,
48664889
setTerminalOpen,
48674890
runProjectScript,

‎apps/web/src/components/ThreadTerminalDrawer.tsx‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
type ThreadTerminalGroup,
6060
} from "../types";
6161
import { readLocalApi } from "~/localApi";
62+
import { confirmTerminalClose } from "~/lib/terminalCloseConfirm";
6263
import { useClientSettings } from "../hooks/useSettings";
6364
import { useLocalStorage } from "../hooks/useLocalStorage";
6465
import { useAttachedTerminalSession } from "../state/terminalSessions";
@@ -1275,24 +1276,10 @@ export default function ThreadTerminalDrawer({
12751276
}, [onNewTerminal]);
12761277
const confirmCloseTerminal = useCallback(
12771278
(terminalId: string) => {
1278-
const localApi = readLocalApi();
1279-
const close = () => onCloseTerminal(terminalId);
1280-
if (!localApi) {
1281-
close();
1282-
return;
1283-
}
12841279
const label = terminalLabelById.get(terminalId) ?? getTerminalLabel(terminalId);
1285-
void localApi.dialogs
1286-
.confirm(
1287-
[
1288-
`Close terminal "${label}"?`,
1289-
"This stops the running process and clears its history.",
1290-
].join("\n"),
1291-
{ variant: "destructive" },
1292-
)
1293-
.then((confirmed) => {
1294-
if (confirmed) close();
1295-
});
1280+
void confirmTerminalClose(label).then((confirmed) => {
1281+
if (confirmed) onCloseTerminal(terminalId);
1282+
});
12961283
},
12971284
[onCloseTerminal, terminalLabelById],
12981285
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { readLocalApi } from "~/localApi";
2+
3+
/**
4+
* Shared confirmation for every user-initiated terminal close (drawer buttons,
5+
* panel buttons, and the `terminal.close` keybinding). Auto-exit cleanup skips
6+
* this path and closes directly.
7+
*/
8+
export async function confirmTerminalClose(label: string): Promise<boolean> {
9+
const localApi = readLocalApi();
10+
if (!localApi) return true;
11+
return localApi.dialogs.confirm(
12+
[`Close terminal "${label}"?`, "This stops the running process and clears its history."].join(
13+
"\n",
14+
),
15+
{ variant: "destructive" },
16+
);
17+
}

0 commit comments

Comments
 (0)