Skip to content

Commit 809c229

Browse files
posthog[bot]PostHog Codejonathanlab
authored andcommitted
fix(terminal): focus xterm on first click and on attach (#2132)
Co-authored-by: PostHog Code <code@posthog.com> Co-authored-by: Jonathan Mieloo <32547391+jonathanlab@users.noreply.github.com>
1 parent b55624f commit 809c229

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • apps/code/src/renderer/features/terminal/components

apps/code/src/renderer/features/terminal/components/Terminal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function Terminal({
5151
if (!terminalRef.current) return;
5252

5353
terminalManager.attach(sessionId, terminalRef.current);
54+
terminalManager.focus(sessionId);
5455

5556
return () => {
5657
terminalManager.detach(sessionId);
@@ -111,12 +112,13 @@ export function Terminal({
111112
};
112113
}, [sessionId, onReady, onExit]);
113114

114-
const handleClick = useCallback(() => {
115+
// mousedown so the xterm textarea is focused before the browser's native focus shift, not after.
116+
const handleMouseDown = useCallback(() => {
115117
terminalManager.focus(sessionId);
116118
}, [sessionId]);
117119

118120
return (
119-
<Box onClick={handleClick} className="relative h-full p-3">
121+
<Box onMouseDown={handleMouseDown} className="relative h-full p-3">
120122
<div ref={terminalRef} className="h-full w-full" />
121123
<style>
122124
{`

0 commit comments

Comments
 (0)