From edf9dc92794d7322e5cf20e6409b1902e9bcf04e Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 16 Oct 2024 20:03:50 -0700 Subject: [PATCH] thread switching --- extensions/void/src/sidebar/SidebarChat.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/void/src/sidebar/SidebarChat.tsx b/extensions/void/src/sidebar/SidebarChat.tsx index 272a369c..1ddbd9c5 100644 --- a/extensions/void/src/sidebar/SidebarChat.tsx +++ b/extensions/void/src/sidebar/SidebarChat.tsx @@ -85,13 +85,20 @@ export const SidebarChat = () => { const abortFnRef = useRef<(() => void) | null>(null) // higher level state - const { allThreads, currentThread, addMessageToHistory, startNewThread, } = useThreads() + const { allThreads, currentThread, addMessageToHistory, startNewThread, switchToThread } = useThreads() const { voidConfig } = useVoidConfig() // if they pressed the + to add a new chat useOnVSCodeMessage('startNewThread', (m) => { - if (currentThread?.messages.length !== 0) - startNewThread() + // find a thread with 0 messages and switch to it + for (let threadId in allThreads) { + if (allThreads[threadId].messages.length === 0) { + switchToThread(threadId) + return + } + } + // start a new thread + startNewThread() }) // if user pressed ctrl+l, add their selection to the sidebar