Skip to content

Commit

Permalink
Implement autocomplete hiding on empty activeInput + remove logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiesel committed Jun 29, 2021
1 parent 1c71795 commit 39d96c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
29 changes: 9 additions & 20 deletions ts/editor/TagEditor.svelte
Expand Up @@ -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;
Expand Down Expand Up @@ -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--;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
}
</script>

<StickyBottom>
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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}
</ButtonToolbar>
</StickyBottom>

Expand Down
3 changes: 2 additions & 1 deletion ts/editor/TagInput.svelte
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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}
/>
Expand Down

0 comments on commit 39d96c9

Please sign in to comment.