fix(terminal): focus xterm on first click and on attach#2132
Merged
Conversation
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
Contributor
|
Reviews (1): Last reviewed commit: "Merge branch 'main' into posthog-code/fi..." | Re-trigger Greptile |
jonathanlab
approved these changes
May 14, 2026
MattBro
pushed a commit
that referenced
this pull request
May 14, 2026
Co-authored-by: PostHog Code <code@posthog.com> Co-authored-by: Jonathan Mieloo <32547391+jonathanlab@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
James reported that clicking into the terminal didn't put the cursor in the right place to start typing — he had to click a second time before keystrokes registered.
The root cause was in
Terminal.tsx:<Box>usedonClickto callterminalManager.focus(). React's syntheticclickfires after the browser's native focus handling on mousedown/mouseup, so when the click landed on the padding (or anywhere outside the xterm canvas), focus had already shifted off the xterm helper textarea by the time we tried to put it back.Terminal, butattach()never calledterm.focus(), so the terminal panel never auto-focused on appear.Changes
apps/code/src/renderer/features/terminal/components/Terminal.tsxonClick→onMouseDownso focus is set before the browser's native focus shift, not after.terminalManager.focus(sessionId)right afterattach()so opening/switching to a terminal tab focuses the xterm immediately.apps/code/src/renderer/features/sessions/components/SessionView.tsxconst { isOnline } = useConnectivity()declaration that was blocking the pre-commit typecheck (introduced by fix(sessions): preserve prompt when sending while offline #1971).Test plan
Created with PostHog Code