diff --git a/ts/editor/AutocompleteItem.svelte b/ts/editor/AutocompleteItem.svelte index 6045acf89..198eebda9 100644 --- a/ts/editor/AutocompleteItem.svelte +++ b/ts/editor/AutocompleteItem.svelte @@ -18,6 +18,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html let buttonRef: HTMLButtonElement; + export function scroll() { + /* TODO will not work on Gecko */ + (buttonRef as any)?.scrollIntoViewIfNeeded(false); + + /* buttonRef.scrollIntoView({ behavior: "smooth", block: "start" }); */ + } + onMount(() => dispatch("mount", { button: buttonRef })); diff --git a/ts/editor/WithAutocomplete.svelte b/ts/editor/WithAutocomplete.svelte index fa3bd55f6..44dacb726 100644 --- a/ts/editor/WithAutocomplete.svelte +++ b/ts/editor/WithAutocomplete.svelte @@ -138,6 +138,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html setSelected(index); } } + + let scroll: () => void; + + $: if (scroll) { + scroll(); + } @@ -145,17 +151,31 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {#each suggestionsItems as suggestion, index} - setSelectedAndActive(index)} - on:mouseup={() => { - selectIndex(index); - chooseSelected(); - }} - on:mouseenter={(event) => selectIfMousedown(event, index)} - on:mouseleave={() => (active = false)}>{suggestion} + {#if index === selected} + setSelectedAndActive(index)} + on:mouseup={() => { + selectIndex(index); + chooseSelected(); + }} + on:mouseenter={(event) => selectIfMousedown(event, index)} + on:mouseleave={() => (active = false)} + >{suggestion} + {:else} + setSelectedAndActive(index)} + on:mouseup={() => { + selectIndex(index); + chooseSelected(); + }} + on:mouseenter={(event) => selectIfMousedown(event, index)} + >{suggestion} + {/if} {/each}