From 285c4e925795ab5dbe8985e9ef25000b2cd360e3 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 1 Nov 2023 12:19:04 +0100 Subject: [PATCH] Fixed bug where "Searching..." label wouldn't disappear --- src/components/InputSearch.svelte | 2 +- src/components/ModalVault.svelte | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/InputSearch.svelte b/src/components/InputSearch.svelte index 15b4df2..b940547 100644 --- a/src/components/InputSearch.svelte +++ b/src/components/InputSearch.svelte @@ -59,4 +59,4 @@ type="text" /> - + \ No newline at end of file diff --git a/src/components/ModalVault.svelte b/src/components/ModalVault.svelte index 5c3ef27..626f946 100644 --- a/src/components/ModalVault.svelte +++ b/src/components/ModalVault.svelte @@ -29,6 +29,7 @@ import { cacheManager } from '../cache-manager' import { searchEngine } from 'src/search/omnisearch' import { cancelable, CancelablePromise } from 'cancelable-promise' + import { debounce } from 'lodash-es' export let modal: OmnisearchVaultModal export let previousQuery: string | undefined @@ -59,10 +60,7 @@ createInCurrentPaneKey = 'shift ↵' } $: if (searchQuery) { - searching = true - updateResults().then(() => { - searching = false - }) + updateResultsDebounced() } else { searching = false resultNotes = [] @@ -79,11 +77,11 @@ indexingStepDesc = 'Indexing files...' break case IndexingStepType.WritingCache: - updateResults() + updateResultsDebounced() indexingStepDesc = 'Updating cache...' break default: - updateResults() + updateResultsDebounced() indexingStepDesc = '' break } @@ -102,6 +100,7 @@ eventBus.on('vault', Action.PrevSearchHistory, prevSearchHistory) eventBus.on('vault', Action.NextSearchHistory, nextSearchHistory) await NotesIndex.refreshIndex() + await updateResultsDebounced() }) onDestroy(() => { @@ -129,6 +128,7 @@ let cancelableQuery: CancelablePromise | null = null async function updateResults() { + searching = true // If search is already in progress, cancel it and start a new one if (cancelableQuery) { cancelableQuery.cancel() @@ -143,8 +143,11 @@ resultNotes = await cancelableQuery selectedIndex = 0 await scrollIntoView() + searching = false } + const updateResultsDebounced = debounce(updateResults, 100) + function onClick(evt?: MouseEvent | KeyboardEvent) { if (!selectedNote) return if (evt?.ctrlKey) {