diff --git a/src/components/Terminal.tsx b/src/components/Terminal.tsx index 3f573701..7f26d6e9 100644 --- a/src/components/Terminal.tsx +++ b/src/components/Terminal.tsx @@ -48,12 +48,12 @@ export function Terminal({ projectId, onClose, className }: TerminalProps) { }]); }, [projectId, fs, git]); - // Auto-scroll to bottom when new lines are added + // Auto-scroll to bottom when new lines are added or execution state changes useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } - }, [lines]); + }, [lines, isExecuting]); // Focus input when component mounts useEffect(() => { @@ -62,6 +62,13 @@ export function Terminal({ projectId, onClose, className }: TerminalProps) { } }, []); + // Refocus input after command execution + useEffect(() => { + if (!isExecuting && inputRef.current) { + inputRef.current.focus(); + } + }, [isExecuting]); + const addLine = useCallback((type: TerminalLine['type'], content: string) => { const newLine: TerminalLine = { id: Date.now().toString() + Math.random(), @@ -164,6 +171,13 @@ export function Terminal({ projectId, onClose, className }: TerminalProps) { return `${projectId}:${relativePath}$`; }; + // Focus input when clicking anywhere in the terminal + const handleTerminalClick = useCallback(() => { + if (inputRef.current) { + inputRef.current.focus(); + } + }, []); + return (