@devries-cameron20 / t3code-1 / commits / 764fff2efc
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): chat shortcuts live with the hooks that own their actions (#23097)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 14:39 UTC 764fff2efcb7123a0518c6b9b768f2f984d08b23
6 files changed +221 -192
apps/web/src/components/ChatView.tsx
+14 -122
@@ -47,13 +47,12 @@ import type { UsageLimitSourceSnapshots } from "@t3tools/contracts";
47 import { feedbackBannerItem } from "./chat/ComposerFeedback";
48 import { useUsageLimitsPanel } from "./chat/useUsageLimitsPanel";
49 import { useWorktreeSetup } from "./chat/useWorktreeSetup";
50 -import { useChatShortcuts, type ChatShortcutHandler } from "./chat/useChatShortcuts";
50 +import { useChatShortcuts } from "./chat/useChatShortcuts";
51 import * as Schema from "effect/Schema";
52 import {
53 AuthOrchestrationOperateScope,
54 AuthSourceControlWriteScope,
55 AuthPreviewOperateScope,
56 - AuthTerminalReadScope,
56 AuthTerminalOperateScope,
57 type AssistantCitation,
58 type ChatFileAttachment,
@@ -71,7 +70,6 @@ import {
70 resolveIdleCompaction,
71 RuntimeMode,
72 } from "@t3tools/contracts";
74 -import { useThreadActions } from "../hooks/useThreadActions";
73 import {
74 deriveProviderSubagentStatus,
75 deriveReportedModelSelection,
@@ -138,7 +136,6 @@ import { useWorkspaceMutationRefresh } from "../hooks/useWorkspaceMutationRefres
136 import { DEFAULT_INTERACTION_MODE, type ChatMessage } from "../types";
137 import { useTheme } from "../hooks/useTheme";
138 import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
141 -import { settleAndAdvance } from "../settleAndAdvance";
139 import { subscribeSnapShotComposerFocus } from "../lib/desktopSnapShot";
140 import { useMediaQuery } from "../hooks/useMediaQuery";
141 import { FileMetadataThreadProvider } from "../hooks/FileMetadataThreadProvider";
@@ -411,10 +408,8 @@ export default function ChatView(props: ChatViewProps) {
408 } = props;
409 const canOperateThread = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope);
410 const canOperateTerminal = useEnvironmentScope(environmentId, AuthTerminalOperateScope);
414 - const canReadTerminal = useEnvironmentScope(environmentId, AuthTerminalReadScope);
411 const draftId = routeKind === "draft" ? props.draftId : null;
412 const handleNewThread = useNewThreadHandler();
417 - const { settleThread, pinThread, confirmAndUnpinThread } = useThreadActions();
413 const routeThreadRef = scopeThreadRef(environmentId, threadId);
414 const routeThreadKey = scopedThreadKey(routeThreadRef);
415 const currentRouteThreadKeyRef = useRef<string | null>(routeThreadKey);
@@ -1847,17 +1842,13 @@ export default function ChatView(props: ChatViewProps) {
1842 addTerminalContextToDraftStable,
1843 addTerminalSurfaceStable,
1844 closePanelTerminalStable,
1850 - createNewTerminalStable,
1845 lastInvokedScriptByProjectId,
1852 - requestClosePanelTerminalStable,
1853 - requestCloseTerminalStable,
1846 runProjectScriptStable,
1847 runShellCommandStable,
1856 - setTerminalOpenStable,
1848 splitPanelTerminalStable,
1849 splitPanelTerminalVerticalStable,
1859 - splitTerminalStable,
1850 toggleTerminalVisibilityStable,
1851 + shortcuts: terminalShortcuts,
1852 } = useChatTerminalActions({
1853 environmentId,
1854 composerRef,
@@ -2382,7 +2373,6 @@ export default function ChatView(props: ChatViewProps) {
2373 },
2374 );
2375 };
2385 - const copyActiveThreadReferenceStable = useStableCallback(copyActiveThreadReference);
2376 const pullRequestPanelTarget = activeThread
2377 ? threadPullRequestPanelTarget({
2378 projectId: activeThread.projectId,
@@ -2404,12 +2394,12 @@ export default function ChatView(props: ChatViewProps) {
2394 createBrowserSurfaceStable,
2395 moveRightPanelSurfaceStable,
2396 onOpenTurnDiffStable,
2407 - onToggleDiffStable,
2397 openChangesFromThreadPanelStable,
2398 openFileSurfaceStable,
2399 toggleRightPanelMaximizedStable,
2400 toggleRightPanelStable,
2401 toggleThreadPanelStable,
2402 + shortcuts: rightPanelShortcuts,
2403 } = useRightPanelActions({
2404 activeThreadRef,
2405 activeProject,
@@ -2434,29 +2424,26 @@ export default function ChatView(props: ChatViewProps) {
2424 explicitDiffOpenRef,
2425 setTerminalFocusRequestId,
2426 onDiffPanelOpen,
2427 + closeRightPanelSurface,
2428 });
2429 const pullRequestSurfaceAvailable = supportsPullRequests && pullRequestPanelTarget !== null;
2430 const nowMinute = useNowMinute();
2431 const {
2432 acknowledgeActiveThreadWoke,
2433 activeBranchMismatchKey,
2443 - activeThreadPinned,
2444 - activeThreadSettled,
2434 backgroundWorkBanner,
2435 childInputBanner,
2436 goalBanner,
2437 handleSwitchCheckoutToThread,
2438 handleSwitchCheckoutToThreadStable,
2450 - handleUnsettleActiveThreadStable,
2439 isRestoringThreadBranch,
2440 onOpenRelatedThread,
2441 onOpenRelatedThreadStable,
2442 sendStandaloneCommand,
2443 setBranchMismatchDismissTick,
2444 showBranchMismatchBanner,
2457 - supportsPinning,
2458 - supportsSettlement,
2445 threadStatusLine,
2446 + shortcuts: threadLifecycleShortcuts,
2447 } = useThreadLifecycle({
2448 environmentId,
2449 routeThreadKey,
@@ -2705,120 +2692,31 @@ export default function ChatView(props: ChatViewProps) {
2692 const threadFindControlsRef = useRef<ThreadFindControls | null>(null);
2693 const [isThreadFindActive, setIsThreadFindActive] = useState(false);
2694 const openThreadFind = () => threadFindControlsRef.current?.open();
2708 - const openThreadFindStable = useStableCallback(openThreadFind);
2695 const closeThreadFind = () => threadFindControlsRef.current?.close();
2710 - const closeThreadFindStable = useStableCallback(closeThreadFind);
2696
2712 - const toastPinFailure = (title: string) => (result: AtomCommandResult<unknown, unknown>) => {
2713 - if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
2714 - const error = squashAtomCommandFailure(result);
2715 - toastManager.add(
2716 - stackedThreadToast({
2717 - type: "error",
2718 - title,
2719 - description: error instanceof Error ? error.message : "An error occurred.",
2720 - }),
2721 - );
2722 - };
2723 - const openTerminalIfClosed = () => {
2724 - if (!terminalUiState.terminalOpen) setTerminalOpenStable(true);
2725 - };
2726 - const openComposerControl = (command: Parameters<ChatComposerHandle["openControl"]>[0]) =>
2727 - (({ event }) => {
2728 - if (!event.repeat) composerRef.current?.openControl(command);
2729 - }) satisfies ChatShortcutHandler;
2697 useChatShortcuts({
2698 enabled: activeThreadId !== null,
2699 keybindings,
2700 scriptKeybindings,
2734 - getShortcutContext: getShortcutContextStable,
2701 + getShortcutContext,
2702 threadFindActive: isThreadFindActive,
2736 - typeIntoComposer: (key) => composerRef.current?.insertTextAtEnd(key) === true,
2703 + composerRef,
2704 + branchToolbarRef,
2705 closeThreadFind: () => {
2738 - closeThreadFindStable();
2706 + closeThreadFind();
2707 focusComposerStable();
2708 },
2709 commands: {
2710 + ...terminalShortcuts,
2711 + ...rightPanelShortcuts,
2712 + ...threadLifecycleShortcuts,
2713 "thread.copyReference": ({ event }) => {
2743 - if (!event.repeat) copyActiveThreadReferenceStable();
2744 - },
2745 - "thread.settle": () => {
2746 - if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return false;
2747 - if (!isServerThread || !activeThreadRef || !supportsSettlement) return;
2748 - if (activeThreadSettled) {
2749 - void handleUnsettleActiveThreadStable();
2750 - return;
2751 - }
2752 - if (settleAndAdvance(activeThreadRef)) return;
2753 - void settleThread(activeThreadRef).then(toastPinFailure("Failed to settle thread"));
2754 - },
2755 - "thread.pin": () => {
2756 - if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return false;
2757 - if (!isServerThread || !activeThreadRef || !supportsPinning) return;
2758 - void (
2759 - activeThreadPinned ? confirmAndUnpinThread(activeThreadRef) : pinThread(activeThreadRef)
2760 - ).then(
2761 - toastPinFailure(activeThreadPinned ? "Failed to unpin thread" : "Failed to pin thread"),
2762 - );
2763 - },
2764 - "terminal.toggle": () => {
2765 - if (!terminalUiState.terminalOpen && !canReadTerminal && !canOperateTerminal) return false;
2766 - toggleTerminalVisibilityStable();
2714 + if (!event.repeat) copyActiveThreadReference();
2715 },
2716 "chat.find": () => {
2717 if (!isServerThread || serverConfig?.threadFind !== true) return false;
2770 - openThreadFindStable();
2771 - },
2772 - "rightPanel.toggle": () => toggleRightPanelStable(),
2773 - "rightPanel.toggleMaximized": ({ event }) => {
2774 - if (!event.repeat) toggleRightPanelMaximizedStable();
2718 + openThreadFind();
2719 },
2776 - "threadPanel.toggle": () => toggleThreadPanelStable(),
2777 - "rightPanel.close": ({ event }) => {
2778 - if (!activeRightPanelSurface) return false;
2779 - if (!event.repeat) closeRightPanelSurfaceStable(activeRightPanelSurface);
2780 - },
2781 - "terminal.split": ({ terminalFocusOwner }) => {
2782 - if (!canOperateTerminal) return false;
2783 - if (terminalFocusOwner === "right-panel") return void splitPanelTerminalStable();
2784 - openTerminalIfClosed();
2785 - splitTerminalStable();
2786 - },
2787 - "terminal.splitVertical": ({ terminalFocusOwner }) => {
2788 - if (!canOperateTerminal) return false;
2789 - if (terminalFocusOwner === "right-panel") return void splitPanelTerminalStable("vertical");
2790 - openTerminalIfClosed();
2791 - splitTerminalStable("vertical");
2792 - },
2793 - "terminal.close": ({ terminalFocusOwner }) => {
2794 - if (!canOperateTerminal) return false;
2795 - if (terminalFocusOwner === "right-panel" && activeRightPanelSurface?.kind === "terminal") {
2796 - requestClosePanelTerminalStable(activeRightPanelSurface.activeTerminalId);
2797 - return;
2798 - }
2799 - if (terminalUiState.terminalOpen)
2800 - requestCloseTerminalStable(terminalUiState.activeTerminalId);
2801 - },
2802 - "terminal.new": ({ terminalFocusOwner }) => {
2803 - if (!canOperateTerminal) return false;
2804 - if (terminalFocusOwner === "right-panel") return void addTerminalSurfaceStable();
2805 - openTerminalIfClosed();
2806 - createNewTerminalStable();
2807 - },
2808 - "diff.toggle": () => onToggleDiffStable(),
2809 - "modelPicker.toggle": ({ event }) => {
2810 - if (!event.repeat) composerRef.current?.toggleModelPicker();
2811 - },
2812 - "composer.increaseEffort": ({ event }) => {
2813 - if (!event.repeat) composerRef.current?.stepReasoningEffort(1);
2814 - },
2815 - "composer.decreaseEffort": ({ event }) => {
2816 - if (!event.repeat) composerRef.current?.stepReasoningEffort(-1);
2817 - },
2818 - "composer.host": openComposerControl("composer.host"),
2819 - "composer.effort": openComposerControl("composer.effort"),
2820 - "composer.mode": openComposerControl("composer.mode"),
2821 - "composer.workspace": openComposerControl("composer.workspace"),
2720 "composer.cycleHost": ({ event }) => {
2721 if (!canChangeEnvironment) return false;
2722 if (event.repeat) return;
@@ -2829,12 +2727,6 @@ export default function ChatView(props: ChatViewProps) {
2727 const next = logicalProjectEnvironments[(index + 1) % logicalProjectEnvironments.length];
2728 if (next) onEnvironmentChangeStable(next.environmentId);
2729 },
2832 - "composer.branch": ({ event }) => {
2833 - if (!event.repeat) branchToolbarRef.current?.openBranchPicker();
2834 - },
2835 - "composer.previousWorktree": ({ event }) => {
2836 - if (!event.repeat) branchToolbarRef.current?.usePreviousWorktree();
2837 - },
2730 "thread.steerQueuedMessage": ({ event }) =>
2731 routeKind !== "draft" && queuedRunsControlRef.current?.steerNext(event.repeat) === true,
2732 "thread.editQueuedMessage": ({ event }) =>
apps/web/src/components/chat/composerShortcuts.ts new
+38
@@ -0,0 +1,38 @@
1 +import type { ComposerHandleRef } from "../../composerHandleContext";
2 +import type { BranchToolbarHandle } from "../BranchToolbar";
3 +import type { ChatComposerHandle } from "./ChatComposer";
4 +import type { ChatShortcutCommands } from "./useChatShortcuts";
5 +
6 +const openControl =
7 + (composerRef: ComposerHandleRef, control: Parameters<ChatComposerHandle["openControl"]>[0]) =>
8 + ({ event }: { readonly event: KeyboardEvent }) => {
9 + if (!event.repeat) composerRef.current?.openControl(control);
10 + };
11 +
12 +/** Chords that open or step the composer's controls and its branch toolbar. Held keys do not repeat them. */
13 +export function composerShortcutCommands(
14 + composerRef: ComposerHandleRef,
15 + branchToolbarRef: { readonly current: BranchToolbarHandle | null },
16 +): ChatShortcutCommands {
17 + return {
18 + "modelPicker.toggle": ({ event }) => {
19 + if (!event.repeat) composerRef.current?.toggleModelPicker();
20 + },
21 + "composer.increaseEffort": ({ event }) => {
22 + if (!event.repeat) composerRef.current?.stepReasoningEffort(1);
23 + },
24 + "composer.decreaseEffort": ({ event }) => {
25 + if (!event.repeat) composerRef.current?.stepReasoningEffort(-1);
26 + },
27 + "composer.host": openControl(composerRef, "composer.host"),
28 + "composer.effort": openControl(composerRef, "composer.effort"),
29 + "composer.mode": openControl(composerRef, "composer.mode"),
30 + "composer.workspace": openControl(composerRef, "composer.workspace"),
31 + "composer.branch": ({ event }) => {
32 + if (!event.repeat) branchToolbarRef.current?.openBranchPicker();
33 + },
34 + "composer.previousWorktree": ({ event }) => {
35 + if (!event.repeat) branchToolbarRef.current?.usePreviousWorktree();
36 + },
37 + } satisfies ChatShortcutCommands;
38 +}
apps/web/src/components/chat/useChatShortcuts.ts
+69 -64
@@ -1,5 +1,5 @@
1 import type { KeybindingCommand, ResolvedKeybindingsConfig } from "@t3tools/contracts";
2 -import { useEffect, useLayoutEffect, useRef } from "react";
2 +import { useEffect, useEffectEvent } from "react";
3 import { isCommandPaletteOpen } from "../../commandPaletteBus";
4 import { resolveChatShortcutCommand, type ShortcutMatchContext } from "../../keybindings";
5 import { isTerminalCloseConfirmPending } from "../../lib/terminalCloseConfirm";
@@ -8,7 +8,10 @@ import {
8 preventTerminalCloseShortcut,
9 } from "../../lib/terminalCloseShortcut";
10 import { getTerminalFocusOwner, type TerminalFocusOwner } from "../../lib/terminalFocus";
11 +import type { ComposerHandleRef } from "../../composerHandleContext";
12 +import type { BranchToolbarHandle } from "../BranchToolbar";
13 import { shouldTypeToFocusComposer } from "./composerFocusRedirect";
14 +import { composerShortcutCommands } from "./composerShortcuts";
15
16 /** Runs a command. Returning false lets the key event through untouched. */
17 export type ChatShortcutHandler = (context: {
@@ -16,6 +19,8 @@ export type ChatShortcutHandler = (context: {
19 readonly terminalFocusOwner: TerminalFocusOwner | null;
20 }) => boolean | void;
21
22 +export type ChatShortcutCommands = Partial<Record<KeybindingCommand, ChatShortcutHandler>>;
23 +
24 export interface ChatShortcutsInput {
25 readonly enabled: boolean;
26 readonly keybindings: ResolvedKeybindingsConfig;
@@ -24,83 +29,83 @@ export interface ChatShortcutsInput {
29 readonly modelPickerOpen: boolean;
30 };
31 readonly threadFindActive: boolean;
27 - /** Types a printable key into the composer; false when it could not take it. */
28 - readonly typeIntoComposer: (key: string) => boolean;
32 + /** Takes type-to-focus keys and the composer and branch toolbar chords. */
33 + readonly composerRef: ComposerHandleRef;
34 + readonly branchToolbarRef: { readonly current: BranchToolbarHandle | null };
35 readonly closeThreadFind: () => void;
30 - readonly commands: Partial<Record<KeybindingCommand, ChatShortcutHandler>>;
36 + readonly commands: ChatShortcutCommands;
37 /** Handles commands not in `commands`, such as project scripts. */
38 readonly fallback: (command: KeybindingCommand) => ChatShortcutHandler | undefined;
39 }
40
41 /**
42 * The chat's window keyboard shortcuts, plus Escape closing thread find.
37 - * Listeners attach once and read the latest input on each event, so handlers
43 + * Listeners attach once; the effect events read the latest input, so handlers
44 * act on the current render without re-registering on every change.
45 */
46 export function useChatShortcuts(input: ChatShortcutsInput) {
41 - const latest = useRef(input);
42 - useLayoutEffect(() => {
43 - latest.current = input;
44 - });
45 - useEffect(() => {
46 - const handler = (event: KeyboardEvent) => {
47 - const current = latest.current;
48 - const { keybindings } = current;
49 - if (preventRepeatedTerminalCloseShortcut(event, keybindings)) {
50 - event.stopPropagation();
51 - return;
52 - }
53 - if (current.threadFindActive && event.key === "Escape") return;
54 - if (isTerminalCloseConfirmPending() && preventTerminalCloseShortcut(event, keybindings)) {
55 - event.stopPropagation();
56 - return;
57 - }
58 - if (!current.enabled || isCommandPaletteOpen()) return;
59 - const terminalFocusOwner = getTerminalFocusOwner();
60 - if (event.defaultPrevented && terminalFocusOwner === null) return;
61 - const shortcutContext = current.getShortcutContext(event.target);
62 -
63 - if (
64 - !shortcutContext.terminalFocus &&
65 - !shortcutContext.modelPickerOpen &&
66 - shouldTypeToFocusComposer(event) &&
67 - current.typeIntoComposer(event.key)
68 - ) {
69 - event.preventDefault();
70 - event.stopPropagation();
71 - return;
72 - }
47 + const handleShortcut = useEffectEvent((event: KeyboardEvent) => {
48 + const { keybindings } = input;
49 + if (preventRepeatedTerminalCloseShortcut(event, keybindings)) {
50 + event.stopPropagation();
51 + return;
52 + }
53 + if (input.threadFindActive && event.key === "Escape") return;
54 + if (isTerminalCloseConfirmPending() && preventTerminalCloseShortcut(event, keybindings)) {
55 + event.stopPropagation();
56 + return;
57 + }
58 + if (!input.enabled || isCommandPaletteOpen()) return;
59 + const terminalFocusOwner = getTerminalFocusOwner();
60 + if (event.defaultPrevented && terminalFocusOwner === null) return;
61 + const shortcutContext = input.getShortcutContext(event.target);
62
74 - const command = resolveChatShortcutCommand(event, keybindings, current.scriptKeybindings, {
75 - context: shortcutContext,
76 - });
77 - if (!command) return;
78 - const run = current.commands[command] ?? current.fallback(command);
79 - if (!run || run({ event, terminalFocusOwner }) === false) return;
63 + if (
64 + !shortcutContext.terminalFocus &&
65 + !shortcutContext.modelPickerOpen &&
66 + shouldTypeToFocusComposer(event) &&
67 + input.composerRef.current?.insertTextAtEnd(event.key) === true
68 + ) {
69 event.preventDefault();
70 event.stopPropagation();
82 - };
83 - const dismissFind = (event: KeyboardEvent) => {
84 - const current = latest.current;
85 - if (
86 - event.key !== "Escape" ||
87 - !current.threadFindActive ||
88 - event.defaultPrevented ||
89 - event.isComposing ||
90 - event.keyCode === 229 ||
91 - isCommandPaletteOpen()
92 - )
93 - return;
94 - const context = current.getShortcutContext(event.target);
95 - if (context.terminalFocus || context.previewFocus || context.modelPickerOpen) return;
96 - event.preventDefault();
97 - current.closeThreadFind();
98 - };
99 - window.addEventListener("keydown", handler, true);
100 - window.addEventListener("keydown", dismissFind);
71 + return;
72 + }
73 +
74 + const command = resolveChatShortcutCommand(event, keybindings, input.scriptKeybindings, {
75 + context: shortcutContext,
76 + });
77 + if (!command) return;
78 + const run =
79 + input.commands[command] ??
80 + composerShortcutCommands(input.composerRef, input.branchToolbarRef)[command] ??
81 + input.fallback(command);
82 + if (!run || run({ event, terminalFocusOwner }) === false) return;
83 + event.preventDefault();
84 + event.stopPropagation();
85 + });
86 + const dismissFind = useEffectEvent((event: KeyboardEvent) => {
87 + if (
88 + event.key !== "Escape" ||
89 + !input.threadFindActive ||
90 + event.defaultPrevented ||
91 + event.isComposing ||
92 + event.keyCode === 229 ||
93 + isCommandPaletteOpen()
94 + )
95 + return;
96 + const context = input.getShortcutContext(event.target);
97 + if (context.terminalFocus || context.previewFocus || context.modelPickerOpen) return;
98 + event.preventDefault();
99 + input.closeThreadFind();
100 + });
101 + useEffect(() => {
102 + const onKeyDownCapture = (event: KeyboardEvent) => handleShortcut(event);
103 + const onKeyDown = (event: KeyboardEvent) => dismissFind(event);
104 + window.addEventListener("keydown", onKeyDownCapture, true);
105 + window.addEventListener("keydown", onKeyDown);
106 return () => {
102 - window.removeEventListener("keydown", handler, true);
103 - window.removeEventListener("keydown", dismissFind);
107 + window.removeEventListener("keydown", onKeyDownCapture, true);
108 + window.removeEventListener("keydown", onKeyDown);
109 };
110 }, []);
111 }
apps/web/src/components/chat/useChatTerminalActions.ts
+43
@@ -41,6 +41,7 @@ import { useLocalStorage } from "~/hooks/useLocalStorage";
41 import { previewEnvironment } from "../../state/preview";
42 import { readEnvironmentScope } from "../../state/session";
43 import { useAtomCommand } from "../../state/use-atom-command";
44 +import type { ChatShortcutCommands } from "./useChatShortcuts";
45 const SCRIPT_TERMINAL_COLS = 120;
46 const SCRIPT_TERMINAL_ROWS = 30;
47
@@ -388,7 +389,49 @@ export function useChatTerminalActions(input: ChatTerminalActionsInput) {
389 });
390 };
391 const requestClosePanelTerminalStable = useStableCallback(requestClosePanelTerminal);
392 + const openTerminalIfClosed = () => {
393 + if (!terminalUiState.terminalOpen) setTerminalOpen(true);
394 + };
395 + // A focused right-panel terminal takes the split/new/close chords; otherwise they act on the drawer.
396 + const shortcuts = {
397 + "terminal.toggle": () => {
398 + if (
399 + !terminalUiState.terminalOpen &&
400 + !readEnvironmentScope(environmentId, AuthTerminalReadScope) &&
401 + !hasTerminalWriteAccess()
402 + )
403 + return false;
404 + toggleTerminalVisibility();
405 + },
406 + "terminal.split": ({ terminalFocusOwner }) => {
407 + if (!hasTerminalWriteAccess()) return false;
408 + if (terminalFocusOwner === "right-panel") return void splitPanelTerminal();
409 + openTerminalIfClosed();
410 + splitTerminal();
411 + },
412 + "terminal.splitVertical": ({ terminalFocusOwner }) => {
413 + if (!hasTerminalWriteAccess()) return false;
414 + if (terminalFocusOwner === "right-panel") return void splitPanelTerminal("vertical");
415 + openTerminalIfClosed();
416 + splitTerminal("vertical");
417 + },
418 + "terminal.close": ({ terminalFocusOwner }) => {
419 + if (!hasTerminalWriteAccess()) return false;
420 + if (terminalFocusOwner === "right-panel" && activeRightPanelSurface?.kind === "terminal") {
421 + requestClosePanelTerminal(activeRightPanelSurface.activeTerminalId);
422 + return;
423 + }
424 + if (terminalUiState.terminalOpen) requestCloseTerminal(terminalUiState.activeTerminalId);
425 + },
426 + "terminal.new": ({ terminalFocusOwner }) => {
427 + if (!hasTerminalWriteAccess()) return false;
428 + if (terminalFocusOwner === "right-panel") return void addTerminalSurface();
429 + openTerminalIfClosed();
430 + createNewTerminal();
431 + },
432 + } satisfies ChatShortcutCommands;
433 return {
434 + shortcuts,
435 activatePanelTerminalStable,
436 addTerminalContextToDraftStable,
437 addTerminalSurfaceStable,
apps/web/src/components/chat/useRightPanelActions.ts
+17
@@ -30,6 +30,7 @@ import { stackedThreadToast, toastManager } from "../ui/toast";
30 import { openDeviceSetupDialog } from "./ChatOverlayHosts";
31 import { previewEnvironment } from "../../state/preview";
32 import { useAtomCommand } from "../../state/use-atom-command";
33 +import type { ChatShortcutCommands } from "./useChatShortcuts";
34 interface RightPanelActionsInput {
35 readonly activeThreadRef: ScopedThreadRef | null;
36 readonly activeProject: EnvironmentProject | null;
@@ -54,6 +55,7 @@ interface RightPanelActionsInput {
55 readonly explicitDiffOpenRef: { current: ScopedThreadRef | null };
56 readonly setTerminalFocusRequestId: Dispatch<SetStateAction<number>>;
57 readonly onDiffPanelOpen: (() => void) | undefined;
58 + readonly closeRightPanelSurface: (surface: RightPanelSurface) => void;
59 }
60
61 /**
@@ -62,6 +64,7 @@ interface RightPanelActionsInput {
64 */
65 export function useRightPanelActions(input: RightPanelActionsInput) {
66 const {
67 + closeRightPanelSurface,
68 activeThreadRef,
69 activeProject,
70 activeRightPanelSurface,
@@ -290,7 +293,21 @@ export function useRightPanelActions(input: RightPanelActionsInput) {
293 [togglePreviewPanelStable],
294 );
295
296 + const shortcuts = {
297 + "rightPanel.toggle": () => toggleRightPanel(),
298 + "rightPanel.toggleMaximized": ({ event }) => {
299 + if (!event.repeat) toggleRightPanelMaximized();
300 + },
301 + "threadPanel.toggle": () => toggleThreadPanel(),
302 + "rightPanel.close": ({ event }) => {
303 + if (!activeRightPanelSurface) return false;
304 + if (!event.repeat) closeRightPanelSurface(activeRightPanelSurface);
305 + },
306 + "diff.toggle": () => onToggleDiff(),
307 + } satisfies ChatShortcutCommands;
308 +
309 return {
310 + shortcuts,
311 activateRightPanelSurfaceStable,
312 addDeviceSurfaceStable,
313 addDiffSurfaceStable,
apps/web/src/components/chat/useThreadLifecycle.tsx
+40 -6
@@ -23,7 +23,9 @@ import {
23 RuntimeMode,
24 } from "@t3tools/contracts";
25 import { effectiveSnoozed, threadWokeAt } from "@t3tools/client-runtime/state/thread-settled";
26 -import { useAcknowledgeThreadWoke } from "../../hooks/useThreadActions";
26 +import { useAcknowledgeThreadWoke, useThreadActions } from "../../hooks/useThreadActions";
27 +import { settleAndAdvance } from "../../settleAndAdvance";
28 +import type { ChatShortcutCommands } from "./useChatShortcuts";
29 import { resolveThreadLastVisitedAt } from "../Sidebar.logic";
30 import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
31 import { type SetStateAction, useEffect, useRef, useState } from "react";
@@ -148,6 +150,7 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
150 } = input;
151 const navigate = useNavigate();
152 const router = useRouter();
153 + const { settleThread, pinThread, confirmAndUnpinThread } = useThreadActions();
154 const canWriteSourceControl = useEnvironmentScope(environmentId, AuthSourceControlWriteScope);
155 const switchGitRef = useAtomCommand(vcsEnvironment.switchRef, { reportFailure: false });
156 const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {
@@ -558,25 +561,56 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
561 onAction={acknowledgeActiveThreadWokeStable}
562 />
563 ) : null;
564 + const toastThreadActionFailure =
565 + (title: string) => (result: AtomCommandResult<unknown, unknown>) => {
566 + if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
567 + const error = squashAtomCommandFailure(result);
568 + toastManager.add(
569 + stackedThreadToast({
570 + type: "error",
571 + title,
572 + description: error instanceof Error ? error.message : "An error occurred.",
573 + }),
574 + );
575 + };
576 + const shortcuts = {
577 + "thread.settle": () => {
578 + if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return false;
579 + if (!activeThreadShell || !activeThreadRef || !supportsSettlement) return;
580 + if (activeThreadSettled) {
581 + void handleUnsettleActiveThread();
582 + return;
583 + }
584 + if (settleAndAdvance(activeThreadRef)) return;
585 + void settleThread(activeThreadRef).then(toastThreadActionFailure("Failed to settle thread"));
586 + },
587 + "thread.pin": () => {
588 + if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return false;
589 + if (!activeThreadShell || !activeThreadRef || !supportsPinning) return;
590 + void (
591 + activeThreadPinned ? confirmAndUnpinThread(activeThreadRef) : pinThread(activeThreadRef)
592 + ).then(
593 + toastThreadActionFailure(
594 + activeThreadPinned ? "Failed to unpin thread" : "Failed to pin thread",
595 + ),
596 + );
597 + },
598 + } satisfies ChatShortcutCommands;
599 return {
600 + shortcuts,
601 acknowledgeActiveThreadWoke,
602 activeBranchMismatchKey,
564 - activeThreadPinned,
565 - activeThreadSettled,
603 backgroundWorkBanner,
604 childInputBanner,
605 goalBanner,
606 handleSwitchCheckoutToThread,
607 handleSwitchCheckoutToThreadStable,
571 - handleUnsettleActiveThreadStable,
608 isRestoringThreadBranch,
609 onOpenRelatedThread,
610 onOpenRelatedThreadStable,
611 sendStandaloneCommand,
612 setBranchMismatchDismissTick,
613 showBranchMismatchBanner,
578 - supportsPinning,
579 - supportsSettlement,
614 threadStatusLine,
615 };
616 }