From 828d71089214c6f3a34dff71a9cc11b7a4297a13 Mon Sep 17 00:00:00 2001 From: pandadev <70103896+0PandaDEV@users.noreply.github.com> Date: Sat, 15 Mar 2025 17:47:19 +0100 Subject: [PATCH] fix: selector not account for an existing search query --- pages/index.vue | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 824f0e1..0accd10 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -341,10 +341,7 @@ const processSearchQueue = async () => { { id: item.id, timestamp: new Date(item.timestamp) } ) ); - - if (groupedHistory.value.length > 0) { - handleSelection(0, 0, false); - } + } catch (error) { console.error("Search error:", error); } finally { @@ -357,19 +354,31 @@ const processSearchQueue = async () => { const searchHistory = async (query: string): Promise => { searchQuery.value = query; - + if (searchController) { searchController.abort(); } - + searchController = new AbortController(); - + searchQueue.push(query); if (!isProcessingSearch) { processSearchQueue(); } }; +watch( + () => groupedHistory.value, + (newGroupedHistory) => { + if (newGroupedHistory.length > 0) { + handleSelection(0, 0, true); + } else { + selectItem(-1, -1); + } + }, + { deep: true } +); + const pasteSelectedItem = async (): Promise => { if (!selectedItem.value) return; @@ -608,10 +617,6 @@ watch( { flush: "post" } ); -watch(searchQuery, () => { - searchHistory(searchQuery.value); -}); - onMounted(async () => { try { os.value = platform();