@devries-cameron20 / t3code Mirror · read-only / commits / 39ca3ee858
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 25, 06:15 UTC

fix(web): bypass xterm for global terminal shortcuts (#1580)

Ariaj committed Apr 18, 2026 at 01:41 UTC 39ca3ee858e764dba3293aa9cb69452c2265440d
3 files changed +36
apps/web/src/components/ChatView.tsx
+5
@@ -10,6 +10,7 @@ import {
10 type ProjectId,
11 type ProviderApprovalDecision,
12 type ServerProvider,
13 + type ResolvedKeybindingsConfig,
14 type ScopedThreadRef,
15 type ThreadId,
16 type TurnId,
@@ -415,6 +416,7 @@ interface PersistentThreadTerminalDrawerProps {
416 splitShortcutLabel: string | undefined;
417 newShortcutLabel: string | undefined;
418 closeShortcutLabel: string | undefined;
419 + keybindings: ResolvedKeybindingsConfig;
420 onAddTerminalContext: (selection: TerminalContextSelection) => void;
421 }
422
@@ -427,6 +429,7 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
429 splitShortcutLabel,
430 newShortcutLabel,
431 closeShortcutLabel,
432 + keybindings,
433 onAddTerminalContext,
434 }: PersistentThreadTerminalDrawerProps) {
435 const serverThread = useStore(useMemo(() => createThreadSelectorByRef(threadRef), [threadRef]));
@@ -570,6 +573,7 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
573 splitShortcutLabel={visible ? splitShortcutLabel : undefined}
574 newShortcutLabel={visible ? newShortcutLabel : undefined}
575 closeShortcutLabel={visible ? closeShortcutLabel : undefined}
576 + keybindings={keybindings}
577 onActiveTerminalChange={activateTerminal}
578 onCloseTerminal={closeTerminal}
579 onHeightChange={setTerminalHeight}
@@ -3443,6 +3447,7 @@ export default function ChatView(props: ChatViewProps) {
3447 splitShortcutLabel={splitTerminalShortcutLabel ?? undefined}
3448 newShortcutLabel={newTerminalShortcutLabel ?? undefined}
3449 closeShortcutLabel={closeTerminalShortcutLabel ?? undefined}
3450 + keybindings={keybindings}
3451 onAddTerminalContext={addTerminalContextToDraft}
3452 />
3453 ))}
apps/web/src/components/ThreadTerminalDrawer.browser.tsx
+2
@@ -177,6 +177,7 @@ async function mountTerminalViewport(props: {
177 autoFocus={false}
178 resizeEpoch={0}
179 drawerHeight={320}
180 + keybindings={[]}
181 />,
182 { container: host },
183 );
@@ -196,6 +197,7 @@ async function mountTerminalViewport(props: {
197 autoFocus={false}
198 resizeEpoch={0}
199 drawerHeight={320}
200 + keybindings={[]}
201 />,
202 );
203 },
apps/web/src/components/ThreadTerminalDrawer.tsx
+29
@@ -1,6 +1,7 @@
1 import { FitAddon } from "@xterm/addon-fit";
2 import { Plus, SquareSplitHorizontal, TerminalSquare, Trash2, XIcon } from "lucide-react";
3 import {
4 + type ResolvedKeybindingsConfig,
5 type ScopedThreadRef,
6 type TerminalEvent,
7 type TerminalSessionSnapshot,
@@ -29,7 +30,12 @@ import {
30 wrappedTerminalLinkRangeIntersectsBufferLine,
31 } from "../terminal-links";
32 import {
33 + isDiffToggleShortcut,
34 isTerminalClearShortcut,
35 + isTerminalCloseShortcut,
36 + isTerminalNewShortcut,
37 + isTerminalSplitShortcut,
38 + isTerminalToggleShortcut,
39 terminalDeleteShortcutData,
40 terminalNavigationShortcutData,
41 } from "../keybindings";
@@ -255,6 +261,7 @@ interface TerminalViewportProps {
261 autoFocus: boolean;
262 resizeEpoch: number;
263 drawerHeight: number;
264 + keybindings: ResolvedKeybindingsConfig;
265 }
266
267 export function TerminalViewport({
@@ -271,6 +278,7 @@ export function TerminalViewport({
278 autoFocus,
279 resizeEpoch,
280 drawerHeight,
281 + keybindings,
282 }: TerminalViewportProps) {
283 const containerRef = useRef<HTMLDivElement>(null);
284 const terminalRef = useRef<Terminal | null>(null);
@@ -282,6 +290,7 @@ export function TerminalViewport({
290 const selectionActionRequestIdRef = useRef(0);
291 const selectionActionOpenRef = useRef(false);
292 const selectionActionTimerRef = useRef<number | null>(null);
293 + const keybindingsRef = useRef(keybindings);
294 const lastAppliedTerminalEventIdRef = useRef(0);
295 const terminalHydratedRef = useRef(false);
296 const handleSessionExited = useEffectEvent(() => {
@@ -292,6 +301,10 @@ export function TerminalViewport({
301 });
302 const readTerminalLabel = useEffectEvent(() => terminalLabel);
303
304 + useEffect(() => {
305 + keybindingsRef.current = keybindings;
306 + }, [keybindings]);
307 +
308 useEffect(() => {
309 const mount = containerRef.current;
310 if (!mount) return;
@@ -403,6 +416,18 @@ export function TerminalViewport({
416 };
417
418 terminal.attachCustomKeyEventHandler((event) => {
419 + const currentKeybindings = keybindingsRef.current;
420 + const options = { context: { terminalFocus: true, terminalOpen: true } };
421 + if (
422 + isTerminalToggleShortcut(event, currentKeybindings, options) ||
423 + isTerminalSplitShortcut(event, currentKeybindings, options) ||
424 + isTerminalNewShortcut(event, currentKeybindings, options) ||
425 + isTerminalCloseShortcut(event, currentKeybindings, options) ||
426 + isDiffToggleShortcut(event, currentKeybindings, options)
427 + ) {
428 + return false;
429 + }
430 +
431 const navigationData = terminalNavigationShortcutData(event);
432 if (navigationData !== null) {
433 event.preventDefault();
@@ -795,6 +820,7 @@ interface ThreadTerminalDrawerProps {
820 onCloseTerminal: (terminalId: string) => void;
821 onHeightChange: (height: number) => void;
822 onAddTerminalContext: (selection: TerminalContextSelection) => void;
823 + keybindings: ResolvedKeybindingsConfig;
824 }
825
826 interface TerminalActionButtonProps {
@@ -848,6 +874,7 @@ export default function ThreadTerminalDrawer({
874 onCloseTerminal,
875 onHeightChange,
876 onAddTerminalContext,
877 + keybindings,
878 }: ThreadTerminalDrawerProps) {
879 const [drawerHeight, setDrawerHeight] = useState(() => clampDrawerHeight(height));
880 const [resizeEpoch, setResizeEpoch] = useState(0);
@@ -1166,6 +1193,7 @@ export default function ThreadTerminalDrawer({
1193 autoFocus={terminalId === resolvedActiveTerminalId}
1194 resizeEpoch={resizeEpoch}
1195 drawerHeight={drawerHeight}
1196 + keybindings={keybindings}
1197 />
1198 </div>
1199 </div>
@@ -1188,6 +1216,7 @@ export default function ThreadTerminalDrawer({
1216 autoFocus
1217 resizeEpoch={resizeEpoch}
1218 drawerHeight={drawerHeight}
1219 + keybindings={keybindings}
1220 />
1221 </div>
1222 )}