From a6e9d6ae924c703eade122b0ae49bae0b670488c Mon Sep 17 00:00:00 2001 From: lif <1835304752@qq.com> Date: Sun, 28 Dec 2025 10:34:14 +0800 Subject: [PATCH] fix(gui): fix Select binding and empty input handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use bind:value for proper two-way binding with Select component - Handle empty input to clear session when user clears the field - Skip session change if value unchanged to avoid redundant API calls - Track previous session to restore when placeholder selected 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../components/chat/SessionSelector.svelte | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/web/src/lib/components/chat/SessionSelector.svelte b/web/src/lib/components/chat/SessionSelector.svelte index 7c43dc68..e754ecb9 100644 --- a/web/src/lib/components/chat/SessionSelector.svelte +++ b/web/src/lib/components/chat/SessionSelector.svelte @@ -13,26 +13,33 @@ const trimmed = sessionInput.trim(); if (trimmed) { setSession(trimmed); + } else { + // Clear session when input is empty + sessionInput = ''; + setSession(null); } } - async function handleSessionSelect(event: Event) { - const target = event.target as HTMLSelectElement; - const value = target.value; + let previousSessionInput = ''; - // If the placeholder option (empty value) is selected, do not clear the session. - // Instead, keep the current session and restore the input field to it. - if (!value) { - sessionInput = $currentSession ?? ''; + async function handleSessionSelect() { + // If the placeholder option (empty value) is selected, restore to previous value + if (!sessionInput) { + sessionInput = previousSessionInput || $currentSession || ''; return; } - sessionInput = value; - setSession(value); + // Skip if session hasn't changed + if (sessionInput === $currentSession) { + return; + } + + previousSessionInput = sessionInput; + setSession(sessionInput); // Load the selected session's message history so the chat reflects prior context try { - const messages = await sessionAPI.loadSessionMessages(value); + const messages = await sessionAPI.loadSessionMessages(sessionInput); messageStore.set(messages); } catch (error) { console.error('Failed to load session messages:', error); @@ -62,7 +69,7 @@ /> {#if sessionsList.length > 0}