From d3191d7ecbc1410746d4632e358714785e4d804b Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Tue, 29 Jun 2021 13:04:32 +0200 Subject: [PATCH] Implement autocomplete hiding on empty activeInput + remove logging --- ts/editor/TagEditor.svelte | 29 +++++++++-------------------- ts/editor/TagInput.svelte | 3 ++- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index ba51eb9ce..2b2e5681d 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -92,14 +92,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html names.splice(index, 1); const contained = names.indexOf(activeName); - console.log( - "isActiveUnique", - active, - index, - activeName, - JSON.stringify(names), - contained - ); if (contained >= 0) { tags[contained >= index ? contained + 1 : contained].flash(); return false; @@ -149,7 +141,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const deleted = tags.splice(index, 1)[0]; tags = tags; - console.log("dt", activeAfterBlur, index); if (activeAfterBlur !== null && activeAfterBlur > index) { activeAfterBlur--; } @@ -187,8 +178,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } function moveToPreviousTag(index: number): void { - console.log("moveprevious", active, index); - if (isFirst(index)) { return; } @@ -225,7 +214,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } function decideNextActive() { - console.log("dna", active, activeAfterBlur); active = activeAfterBlur; activeAfterBlur = null; } @@ -238,7 +226,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html return event.code === "Backspace" || event.code === "Delete"; } - function update(event: KeyboardEvent, autocomplete: any): void { + function onKeydown(event: KeyboardEvent, autocomplete: any): void { const visible = autocomplete.isVisible(); const printable = isPrintableKey(event); const deletion = isDeletionKey(event); @@ -251,10 +239,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } } - if (activeName.length === 0) { - autocomplete.hide(); - } - switch (event.code) { case "ArrowUp": autocomplete.selectNext(); @@ -288,6 +272,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html break; } } + + function onKeyup(_event: KeyboardEvent, autocomplete: any): void { + if (activeName.length === 0) { + autocomplete.hide(); + } + } @@ -317,7 +307,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html activeName = tag.name; createAutocomplete(activeInput); }} - on:keydown={(event) => update(event, autocomplete)} + on:keydown={(event) => onKeydown(event, autocomplete)} + on:keyup={(event) => onKeyup(event, autocomplete)} on:input={() => updateTagName(tag)} on:tagsplit={({ detail }) => enterBehavior( @@ -360,8 +351,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html class="tag-spacer flex-grow-1 align-self-stretch" on:click={appendEmptyTag} /> - {active} - {activeAfterBlur} diff --git a/ts/editor/TagInput.svelte b/ts/editor/TagInput.svelte index 2ab9773a1..afc3e096a 100644 --- a/ts/editor/TagInput.svelte +++ b/ts/editor/TagInput.svelte @@ -75,8 +75,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html function onBlur(event: Event): void { event.preventDefault(); + normalize(); - console.log("taginput onblur"); if (name.length === 0) { dispatch("tagdelete"); } @@ -182,6 +182,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html on:blur={onBlur} on:keydown={onKeydown} on:keydown + on:keyup on:input on:paste={onPaste} />