From 03d8d3e3532aff566fc9508c9fde736b5b288eed Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 16 Nov 2026 22:39:24 +0900 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 18 +++++++++++------- src/lib/components/chat/Tabs.svelte | 9 ++++++++- src/routes/+layout.svelte | 9 ++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 5bba29ca5a..23e8d46ae0 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -4505,13 +4505,16 @@ const currentHistory = history; processing = 'uploading'; try { - if (files.some((file) => file.status === 'pending' && file.file instanceof File)) { - const _chatId = await getChatId(currentHistory); - if (_chatId === null) return { status: 'rejected' }; - if (history !== currentHistory) return { status: 'rejected' }; - if (!(await messageInput?.uploadPendingFiles(_chatId || (await initChatHandler(history))))) - return { status: 'rejected' }; - } + // Set up the chat before the message is posted and the input cleared, so a refusal + // (e.g. a missing working directory) leaves the draft in place. + const _chatId = await getChatId(currentHistory); + if (_chatId === null) return { status: 'rejected' }; + if (history !== currentHistory) return { status: 'rejected' }; + if ( + files.some((file) => file.status === 'pending' && file.file instanceof File) && + !(await messageInput?.uploadPendingFiles(_chatId || (await initChatHandler(history)))) + ) + return { status: 'rejected' }; if (history !== currentHistory) return { status: 'rejected' }; } catch (error) { toast.error(`${error}`); @@ -5857,6 +5860,7 @@ class:hidden={fullWidthTabs && !mainChatActive} style={fullWidthTabs ? mainChatStyle : undefined} data-main-chat-pane + data-chat-id={$chatId} data-panel-group={fullWidthTabs ? mainChatGroupId : undefined} on:focusin={() => fullWidthTabs && tabs?.focusMainChat()} on:pointerdown={() => fullWidthTabs && tabs?.focusMainChat()} diff --git a/src/lib/components/chat/Tabs.svelte b/src/lib/components/chat/Tabs.svelte index 018d9d90cf..13d7827e0c 100644 --- a/src/lib/components/chat/Tabs.svelte +++ b/src/lib/components/chat/Tabs.svelte @@ -1667,7 +1667,14 @@ } beforeNavigate(({ from, to, cancel, willUnload }) => { - if (from?.url.pathname === to?.url.pathname) return; + if (from?.url.pathname === to?.url.pathname) { + // The router stays on the main chat while other tabs are in front; going there uncovers it. + if (to && location.pathname !== to.url.pathname) { + focusMainChat(); + if (!isLargeScreen) showTabs.set(false); + } + return; + } captureView(); if (viewEntry) void flushChatView(viewEntry); if (willUnload && hasChatViewDrafts()) cancel(); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 254f34454d..3ebc5039dd 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -541,11 +541,10 @@ } } - if ( - !event?.internal && - ((event.chat_id !== $chatId && !$openEmbeddedChatIds.has(event.chat_id) && !$temporaryChat) || - isInBackground) - ) { + const isVisible = !!document + .querySelector(`[data-chat-id="${CSS.escape(event.chat_id)}"]`) + ?.checkVisibility(); + if (!event?.internal && ((!isVisible && !$temporaryChat) || isInBackground)) { if (type === 'chat:completion') { const { done, content, output, title } = data; const displayTitle = title || $i18n.t('New Chat');