mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -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();
|
||||
}
|
||||
|
||||
function onChange(evt: Event) {
|
||||
const oldIdx = parseInt((evt.target as HTMLSelectElement).value, 10);
|
||||
state.setOldIndex(ctx, newIndex, oldIdx);
|
||||
}
|
||||
|
||||
// optimization for big notetypes
|
||||
let active: boolean = false;
|
||||
function activate(evt: Event) {
|
||||
active = true;
|
||||
}
|
||||
|
||||
function onChange(evt: Event) {
|
||||
const oldIdx = parseInt((evt.target as HTMLSelectElement).value, 10);
|
||||
state.setOldIndex(ctx, newIndex, oldIdx);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Row --cols={2}>
|
||||
<Col --col-size={1}>
|
||||
<!-- svelte-ignore a11y-no-onchange -->
|
||||
<select
|
||||
value={$info.getOldIndex(ctx, newIndex)}
|
||||
value={active ? $info.getOldIndex(ctx, newIndex) : 0}
|
||||
class="form-select"
|
||||
on:focusin={activate}
|
||||
on:change={onChange}
|
||||
>
|
||||
{#each $info.getOldNamesIncludingNothing(ctx) as name, idx}
|
||||
<option value={idx}>{name}</option>
|
||||
{/each}
|
||||
{#if active}
|
||||
{#each oldNames as name, idx}
|
||||
<option value={idx}>{name}</option>
|
||||
{/each}
|
||||
{:else}
|
||||
<option value={0}>{current}</option>
|
||||
{/if}
|
||||
</select>
|
||||
</Col>
|
||||
<Col --col-size={1}>
|
||||
|
|
Loading…
Reference in a new issue