mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2025-12-12 13:56:16 +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);
|
const searchFilter = writable<number[] | undefined>(undefined);
|
||||||
|
let currentSearchQuery = $state("");
|
||||||
|
|
||||||
async function search(index: FlexSearch.Index, event: Event) {
|
async function search(index: FlexSearch.Index, event: Event) {
|
||||||
const query = (event.target as HTMLInputElement).value;
|
const query = (event.target as HTMLInputElement).value;
|
||||||
|
currentSearchQuery = query;
|
||||||
searchFilter.set(
|
searchFilter.set(
|
||||||
query && searchIndex
|
query && searchIndex
|
||||||
? ((await index.searchAsync(query)) as number[])
|
? ((await index.searchAsync(query)) as number[])
|
||||||
@@ -194,6 +196,13 @@
|
|||||||
page = 0;
|
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[]) {
|
function insertChord(actions: number[]) {
|
||||||
const id = JSON.stringify(actions);
|
const id = JSON.stringify(actions);
|
||||||
if ($chords.some((it) => JSON.stringify(it.actions) === id)) {
|
if ($chords.some((it) => JSON.stringify(it.actions) === id)) {
|
||||||
@@ -273,6 +282,7 @@
|
|||||||
<input
|
<input
|
||||||
type="search"
|
type="search"
|
||||||
placeholder={$LL.configure.chords.search.PLACEHOLDER(progress)}
|
placeholder={$LL.configure.chords.search.PLACEHOLDER(progress)}
|
||||||
|
value={currentSearchQuery}
|
||||||
oninput={(event) => $searchIndex && search($searchIndex, event)}
|
oninput={(event) => $searchIndex && search($searchIndex, event)}
|
||||||
class:loading={progress !== $chords.length}
|
class:loading={progress !== $chords.length}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user