diff --git a/src/components/GlobalChatPane.tsx b/src/components/GlobalChatPane.tsx index a8f3e2b8..4f1ca611 100644 --- a/src/components/GlobalChatPane.tsx +++ b/src/components/GlobalChatPane.tsx @@ -113,7 +113,7 @@ export function GlobalChatPane() { } }, [providerModel, settings.recentlyUsedModels, setProviderModel]); - // Scroll to bottom when chat opens + // Scroll to bottom and focus textarea when chat opens useEffect(() => { if (isOpen && scrollAreaRef.current) { // Small delay to ensure content is rendered @@ -121,6 +121,8 @@ export function GlobalChatPane() { if (scrollAreaRef.current) { scrollAreaRef.current.scrollTop = scrollAreaRef.current.scrollHeight; } + // Focus the textarea so user can start typing immediately + textareaRef.current?.focus(); }); // Reset scroll tracking when opening userScrolledUp.current = false; diff --git a/src/components/GlobalChatProvider.tsx b/src/components/GlobalChatProvider.tsx index 3ced583c..e86db2ac 100644 --- a/src/components/GlobalChatProvider.tsx +++ b/src/components/GlobalChatProvider.tsx @@ -127,6 +127,7 @@ export function GlobalChatProvider({ children }: GlobalChatProviderProps) { }); let fullContent = ''; + let loadingReleased = false; for await (const chunk of stream) { const delta = chunk.choices[0]?.delta?.content || ''; @@ -143,10 +144,14 @@ export function GlobalChatProvider({ children }: GlobalChatProviderProps) { }); // Check if the stream is finished (finish_reason is set) + // Only release once to avoid multiple state updates const finishReason = chunk.choices[0]?.finish_reason; - if (finishReason) { + if (finishReason && !loadingReleased) { + loadingReleased = true; // Response is complete, release the input immediately setIsLoading(false); + // Break out of the loop - we don't need any more chunks + break; } }