diff --git a/desktop/src/features/terminal/TerminalContext.tsx b/desktop/src/features/terminal/TerminalContext.tsx index 99f6aed007..2b103c8968 100644 --- a/desktop/src/features/terminal/TerminalContext.tsx +++ b/desktop/src/features/terminal/TerminalContext.tsx @@ -35,6 +35,21 @@ export function TerminalProvider({ children }: { children: React.ReactNode }) { }; }, []); + // Focus management: return focus to composer when terminal closes. + const prevOpenRef = React.useRef(isOpen); + React.useEffect(() => { + if (prevOpenRef.current && !isOpen) { + // Terminal just closed — focus the composer. + requestAnimationFrame(() => { + const editor = document.querySelector( + '[data-testid="message-composer"] .ProseMirror', + ); + editor?.focus(); + }); + } + prevOpenRef.current = isOpen; + }, [isOpen]); + const value = React.useMemo( () => ({ isOpen, toggle, close }), [isOpen, toggle, close], diff --git a/desktop/src/features/terminal/TerminalInstance.tsx b/desktop/src/features/terminal/TerminalInstance.tsx index 28bab7c878..37248c492a 100644 --- a/desktop/src/features/terminal/TerminalInstance.tsx +++ b/desktop/src/features/terminal/TerminalInstance.tsx @@ -212,11 +212,12 @@ export function TerminalInstance({ }; }, [channelId, isVisible]); - // Re-fit when visibility changes. + // Re-fit and focus when visibility changes. React.useEffect(() => { if (isVisible && fitAddonRef.current) { requestAnimationFrame(() => { fitAddonRef.current?.fit(); + termRef.current?.focus(); if (sessionIdRef.current && termRef.current) { invoke("terminal_resize", { input: {