mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2025-12-10 21:06:17 +00:00
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:
@@ -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}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user