From 60b1d65351861f11a122f62f75b13c35f3ab0b7b Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Wed, 8 Sep 2021 15:11:53 +0200 Subject: [PATCH] Update Autocomplete position when suggestion selection makes it move to the next row --- ts/editor/TagEditor.svelte | 2 +- ts/editor/TagInput.svelte | 6 ++++-- ts/editor/WithAutocomplete.svelte | 20 ++++++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index a086be324..ad111a320 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -472,7 +472,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html }} on:keydown={onKeydown} on:keyup={onKeyup} - on:input={() => updateTagName(tag)} + on:taginput={() => updateTagName(tag)} on:tagsplit={({ detail }) => enterBehavior(index, detail.start, detail.end)} on:tagadd={() => insertTagKeepFocus(index)} diff --git a/ts/editor/TagInput.svelte b/ts/editor/TagInput.svelte index de6a4083d..941e2d4ee 100644 --- a/ts/editor/TagInput.svelte +++ b/ts/editor/TagInput.svelte @@ -65,8 +65,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html name = name.slice(0, position - 1) + name.slice(position, name.length); await tick(); - setPosition(position - 1); event.preventDefault(); + setPosition(position - 1); + dispatch("taginput"); } } @@ -144,6 +145,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html await tick(); setPosition(positionStart + 1); + dispatch("taginput"); } function onKeydown(event: KeyboardEvent): void { @@ -243,7 +245,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html on:keydown={onKeydown} on:keydown on:keyup - on:input + on:input={() => dispatch("taginput")} on:copy|preventDefault={onCopy} on:paste|preventDefault={onPaste} /> diff --git a/ts/editor/WithAutocomplete.svelte b/ts/editor/WithAutocomplete.svelte index e1695ae3e..6ca16b3dd 100644 --- a/ts/editor/WithAutocomplete.svelte +++ b/ts/editor/WithAutocomplete.svelte @@ -41,7 +41,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html /** * select as currently highlighted item */ - async function selectNext() { + function incrementSelected(): void { if (selected === null) { selected = 0; } else if (selected >= suggestionsItems.length - 1) { @@ -49,11 +49,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } else { selected++; } - - dispatch("select", { selected: suggestionsItems[selected ?? -1] }); } - async function selectPrevious() { + function decrementSelected(): void { if (selected === null) { selected = suggestionsItems.length - 1; } else if (selected === 0) { @@ -61,8 +59,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } else { selected--; } + } + async function updateSelected(): Promise { dispatch("select", { selected: suggestionsItems[selected ?? -1] }); + await tick(); + dropdown.update(); + } + + async function selectNext(): Promise { + incrementSelected(); + await updateSelected(); + } + + async function selectPrevious(): Promise { + decrementSelected(); + await updateSelected(); } /**