feat(web): confirm before closing a terminal (#7592)
This commit is contained in:
1 parent
a354dd9ddc
commit
0508792c57
4 files changed
+198
-13
No files matched your search
@@ -46,7 +46,11 @@ import {
|
||||
import { CHAT_LIST_ANCHOR_OFFSET } from "@t3tools/shared/chatList";
|
||||
import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts";
|
||||
import { truncate } from "@t3tools/shared/String";
|
||||
import { nextTerminalId, resolveTerminalSessionLabel } from "@t3tools/shared/terminalLabels";
|
||||
import {
|
||||
getTerminalLabel,
|
||||
nextTerminalId,
|
||||
resolveTerminalSessionLabel,
|
||||
} from "@t3tools/shared/terminalLabels";
|
||||
import { Debouncer } from "@tanstack/react-pacer";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import {
|
||||
@@ -192,8 +196,12 @@ import {
|
||||
import { useNowMinute } from "../hooks/useNowMinute";
|
||||
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
|
||||
import { resolveAppModelSelectionForInstance } from "../modelSelection";
|
||||
import { confirmTerminalClose, isTerminalCloseConfirmPending } from "../lib/terminalCloseConfirm";
|
||||
import { getTerminalFocusOwner } from "../lib/terminalFocus";
|
||||
import { preventRepeatedTerminalCloseShortcut } from "../lib/terminalCloseShortcut";
|
||||
import {
|
||||
preventRepeatedTerminalCloseShortcut,
|
||||
preventTerminalCloseShortcut,
|
||||
} from "../lib/terminalCloseShortcut";
|
||||
import { resolveNewDraftStartFromOrigin } from "../lib/chatThreadActions";
|
||||
import {
|
||||
derivePhysicalProjectKey,
|
||||
@@ -3453,6 +3461,24 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
},
|
||||
[activeRightPanelSurface, activeThreadRef, closeTerminalMutation, storeCloseTerminal],
|
||||
);
|
||||
const requestCloseTerminal = useCallback(
|
||||
(terminalId: string) => {
|
||||
const label = activeTerminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId);
|
||||
void confirmTerminalClose([label]).then((confirmed) => {
|
||||
if (confirmed) closeTerminal(terminalId);
|
||||
});
|
||||
},
|
||||
[activeTerminalLabelsById, closeTerminal],
|
||||
);
|
||||
const requestClosePanelTerminal = useCallback(
|
||||
(terminalId: string) => {
|
||||
const label = activeTerminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId);
|
||||
void confirmTerminalClose([label]).then((confirmed) => {
|
||||
if (confirmed) closePanelTerminal(terminalId);
|
||||
});
|
||||
},
|
||||
[activeTerminalLabelsById, closePanelTerminal],
|
||||
);
|
||||
const activateRightPanelSurface = useCallback(
|
||||
(surface: RightPanelSurface) => {
|
||||
if (!activeThreadRef) return;
|
||||
@@ -3527,11 +3553,33 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
const closeRightPanelSurface = useCallback(
|
||||
(surface: RightPanelSurface) => {
|
||||
if (!activeThreadRef) return;
|
||||
cleanupRightPanelSurfaces([surface]);
|
||||
useRightPanelStore.getState().closeSurface(activeThreadRef, surface.id);
|
||||
syncActivePreviewSurface();
|
||||
const finishClose = () => {
|
||||
cleanupRightPanelSurfaces([surface]);
|
||||
useRightPanelStore.getState().closeSurface(activeThreadRef, surface.id);
|
||||
syncActivePreviewSurface();
|
||||
};
|
||||
if (surface.kind !== "terminal") {
|
||||
finishClose();
|
||||
return;
|
||||
}
|
||||
const activeLabel =
|
||||
activeTerminalLabelsById.get(surface.activeTerminalId) ??
|
||||
getTerminalLabel(surface.activeTerminalId);
|
||||
const otherLabels = surface.terminalIds
|
||||
.filter((terminalId) => terminalId !== surface.activeTerminalId)
|
||||
.map(
|
||||
(terminalId) => activeTerminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId),
|
||||
);
|
||||
void confirmTerminalClose([activeLabel, ...otherLabels]).then((confirmed) => {
|
||||
if (confirmed) finishClose();
|
||||
});
|
||||
},
|
||||
[activeThreadRef, cleanupRightPanelSurfaces, syncActivePreviewSurface],
|
||||
[
|
||||
activeThreadRef,
|
||||
activeTerminalLabelsById,
|
||||
cleanupRightPanelSurfaces,
|
||||
syncActivePreviewSurface,
|
||||
],
|
||||
);
|
||||
const closeOtherRightPanelSurfaces = useCallback(
|
||||
(surface: RightPanelSurface) => {
|
||||
@@ -4724,6 +4772,13 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
// While a close confirmation is open, terminal focus has moved to the
|
||||
// dialog, so a deliberate second close shortcut would otherwise fall
|
||||
// through to the native window/tab close accelerator.
|
||||
if (isTerminalCloseConfirmPending() && preventTerminalCloseShortcut(event, keybindings)) {
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (!activeThreadId || isCommandPaletteOpen()) {
|
||||
return;
|
||||
}
|
||||
@@ -4807,11 +4862,11 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (terminalFocusOwner === "right-panel" && activeRightPanelSurface?.kind === "terminal") {
|
||||
closePanelTerminal(activeRightPanelSurface.activeTerminalId);
|
||||
requestClosePanelTerminal(activeRightPanelSurface.activeTerminalId);
|
||||
return;
|
||||
}
|
||||
if (!terminalUiState.terminalOpen) return;
|
||||
closeTerminal(terminalUiState.activeTerminalId);
|
||||
requestCloseTerminal(terminalUiState.activeTerminalId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4860,8 +4915,8 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
terminalUiState.terminalOpen,
|
||||
terminalUiState.activeTerminalId,
|
||||
activeThreadId,
|
||||
closeTerminal,
|
||||
closePanelTerminal,
|
||||
requestCloseTerminal,
|
||||
requestClosePanelTerminal,
|
||||
createNewTerminal,
|
||||
setTerminalOpen,
|
||||
runProjectScript,
|
||||
|
||||
@@ -59,6 +59,7 @@ import {
|
||||
type ThreadTerminalGroup,
|
||||
} from "../types";
|
||||
import { readLocalApi } from "~/localApi";
|
||||
import { confirmTerminalClose } from "~/lib/terminalCloseConfirm";
|
||||
import { useClientSettings } from "../hooks/useSettings";
|
||||
import { useLocalStorage } from "../hooks/useLocalStorage";
|
||||
import { useAttachedTerminalSession } from "../state/terminalSessions";
|
||||
@@ -1273,6 +1274,15 @@ export default function ThreadTerminalDrawer({
|
||||
const onNewTerminalAction = useCallback(() => {
|
||||
onNewTerminal();
|
||||
}, [onNewTerminal]);
|
||||
const confirmCloseTerminal = useCallback(
|
||||
(terminalId: string) => {
|
||||
const label = terminalLabelById.get(terminalId) ?? getTerminalLabel(terminalId);
|
||||
void confirmTerminalClose([label]).then((confirmed) => {
|
||||
if (confirmed) onCloseTerminal(terminalId);
|
||||
});
|
||||
},
|
||||
[onCloseTerminal, terminalLabelById],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
onHeightChangeRef.current = onHeightChange;
|
||||
@@ -1463,7 +1473,7 @@ export default function ThreadTerminalDrawer({
|
||||
<div className="h-4 w-px bg-border/80" />
|
||||
<TerminalActionButton
|
||||
className="p-1 text-foreground/90 transition-colors hover:bg-accent"
|
||||
onClick={() => onCloseTerminal(resolvedActiveTerminalId)}
|
||||
onClick={() => confirmCloseTerminal(resolvedActiveTerminalId)}
|
||||
label={closeTerminalActionLabel}
|
||||
>
|
||||
<Trash2 className="size-3.25" />
|
||||
@@ -1598,7 +1608,7 @@ export default function ThreadTerminalDrawer({
|
||||
</TerminalActionButton>
|
||||
<TerminalActionButton
|
||||
className="inline-flex h-full items-center border-l border-border/70 px-1 text-foreground/90 transition-colors hover:bg-accent/70"
|
||||
onClick={() => onCloseTerminal(resolvedActiveTerminalId)}
|
||||
onClick={() => confirmCloseTerminal(resolvedActiveTerminalId)}
|
||||
label={closeTerminalActionLabel}
|
||||
>
|
||||
<Trash2 className="size-3.25" />
|
||||
@@ -1668,7 +1678,7 @@ export default function ThreadTerminalDrawer({
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex size-3.5 items-center justify-center rounded text-xs font-medium leading-none text-muted-foreground opacity-0 transition hover:bg-accent hover:text-foreground group-hover:opacity-100"
|
||||
onClick={() => onCloseTerminal(terminalId)}
|
||||
onClick={() => confirmCloseTerminal(terminalId)}
|
||||
aria-label={closeTerminalLabel}
|
||||
/>
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user