mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Initially load option at newIndex and remaining options on focus
Optimization for big notetypes: Should increase efficiency from O(n²) to O(n). Test on notetype with 500 templates shows significant improvement in load time (~10s down to ~1s).
This commit is contained in:
parent
9d1e131e7f
commit
f42beee45c
1 changed files with 14 additions and 9 deletions
|
@ -21,29 +21,34 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
current = oldNames[newIndex] || tr.changeNotetypeNothing();
|
current = oldNames[newIndex] || tr.changeNotetypeNothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onChange(evt: Event) {
|
|
||||||
const oldIdx = parseInt((evt.target as HTMLSelectElement).value, 10);
|
|
||||||
state.setOldIndex(ctx, newIndex, oldIdx);
|
|
||||||
}
|
|
||||||
|
|
||||||
// optimization for big notetypes
|
// optimization for big notetypes
|
||||||
let active: boolean = false;
|
let active: boolean = false;
|
||||||
function activate(evt: Event) {
|
function activate(evt: Event) {
|
||||||
active = true;
|
active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onChange(evt: Event) {
|
||||||
|
const oldIdx = parseInt((evt.target as HTMLSelectElement).value, 10);
|
||||||
|
state.setOldIndex(ctx, newIndex, oldIdx);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Row --cols={2}>
|
<Row --cols={2}>
|
||||||
<Col --col-size={1}>
|
<Col --col-size={1}>
|
||||||
<!-- svelte-ignore a11y-no-onchange -->
|
<!-- svelte-ignore a11y-no-onchange -->
|
||||||
<select
|
<select
|
||||||
value={$info.getOldIndex(ctx, newIndex)}
|
value={active ? $info.getOldIndex(ctx, newIndex) : 0}
|
||||||
class="form-select"
|
class="form-select"
|
||||||
|
on:focusin={activate}
|
||||||
on:change={onChange}
|
on:change={onChange}
|
||||||
>
|
>
|
||||||
{#each $info.getOldNamesIncludingNothing(ctx) as name, idx}
|
{#if active}
|
||||||
<option value={idx}>{name}</option>
|
{#each oldNames as name, idx}
|
||||||
{/each}
|
<option value={idx}>{name}</option>
|
||||||
|
{/each}
|
||||||
|
{:else}
|
||||||
|
<option value={0}>{current}</option>
|
||||||
|
{/if}
|
||||||
</select>
|
</select>
|
||||||
</Col>
|
</Col>
|
||||||
<Col --col-size={1}>
|
<Col --col-size={1}>
|
||||||
|
|
Loading…
Reference in a new issue