From 781fbcb2d8009c0c5bb45394034998de7248f1c4 Mon Sep 17 00:00:00 2001 From: PostHog Code Date: Wed, 13 May 2026 20:25:00 +0000 Subject: [PATCH] fix(terminal): focus xterm on first click and on attach Clicking into the terminal required a second click before typing worked. onClick fires after the browser's native focus handling, so the xterm helper textarea didn't end up focused. Switch to onMouseDown so focus is set before the focus shift, and focus on attach so opening/switching to a terminal tab puts the cursor in the right place immediately. Also remove a duplicate `isOnline` declaration in SessionView that was blocking typecheck. Generated-By: PostHog Code Task-Id: d2835cfc-8408-4791-b028-49313a248a7c --- .../renderer/features/sessions/components/SessionView.tsx | 1 - .../src/renderer/features/terminal/components/Terminal.tsx | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/code/src/renderer/features/sessions/components/SessionView.tsx b/apps/code/src/renderer/features/sessions/components/SessionView.tsx index 05e4de94e..b95675e7d 100644 --- a/apps/code/src/renderer/features/sessions/components/SessionView.tsx +++ b/apps/code/src/renderer/features/sessions/components/SessionView.tsx @@ -250,7 +250,6 @@ export function SessionView({ [onSendPrompt], ); - const { isOnline } = useConnectivity(); const handleBeforeSubmit = useCallback( (text: string, clearEditor: () => void): boolean => { if (!isOnline) { diff --git a/apps/code/src/renderer/features/terminal/components/Terminal.tsx b/apps/code/src/renderer/features/terminal/components/Terminal.tsx index 8ab3e8093..9fe149d88 100644 --- a/apps/code/src/renderer/features/terminal/components/Terminal.tsx +++ b/apps/code/src/renderer/features/terminal/components/Terminal.tsx @@ -51,6 +51,7 @@ export function Terminal({ if (!terminalRef.current) return; terminalManager.attach(sessionId, terminalRef.current); + terminalManager.focus(sessionId); return () => { terminalManager.detach(sessionId); @@ -111,12 +112,13 @@ export function Terminal({ }; }, [sessionId, onReady, onExit]); - const handleClick = useCallback(() => { + // mousedown so the xterm textarea is focused before the browser's native focus shift, not after. + const handleMouseDown = useCallback(() => { terminalManager.focus(sessionId); }, [sessionId]); return ( - +