From 6457fbda76558e43bff54bc6392cfd739e23de0d Mon Sep 17 00:00:00 2001 From: MK Fain Date: Wed, 3 Dec 2025 21:08:00 -0600 Subject: [PATCH] Auto-focus textarea when GlobalChatPane opens When the global chat pane is opened, the textarea is now automatically focused so users can immediately start typing without needing to click on the input field first. --- src/components/GlobalChatPane.tsx | 4 +++- src/components/GlobalChatProvider.tsx | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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; } }