Fix stale search (#189)

Fixes an issue where, after chord list is updated (e.g. by a deletion),
the search results continue to use the old list and indices, resulting
in incorrect search results.
This commit is contained in:
Shane O'Donnell
2025-06-13 07:22:25 -04:00
committed by GitHub
parent bd1c6147fd
commit 087ff36d5d

View File

@@ -183,9 +183,11 @@
}
const searchFilter = writable<number[] | undefined>(undefined);
let currentSearchQuery = $state("");
async function search(index: FlexSearch.Index, event: Event) {
const query = (event.target as HTMLInputElement).value;
currentSearchQuery = query;
searchFilter.set(
query && searchIndex
? ((await index.searchAsync(query)) as number[])
@@ -194,6 +196,13 @@
page = 0;
}
// Re-run search when chords change to fix stale indices
$effect(() => {
if (currentSearchQuery && $searchIndex) {
search($searchIndex, { target: { value: currentSearchQuery } } as any);
}
});
function insertChord(actions: number[]) {
const id = JSON.stringify(actions);
if ($chords.some((it) => JSON.stringify(it.actions) === id)) {
@@ -273,6 +282,7 @@
<input
type="search"
placeholder={$LL.configure.chords.search.PLACEHOLDER(progress)}
value={currentSearchQuery}
oninput={(event) => $searchIndex && search($searchIndex, event)}
class:loading={progress !== $chords.length}
/>