Remove special treatment of last tag

This commit is contained in:
Henrik Giesel 2021-06-26 16:26:42 +02:00
parent e80e6ff34b
commit e68f874c80

View file

@ -19,6 +19,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let tags = initialNames.map((name) => attachId(name)); let tags = initialNames.map((name) => attachId(name));
function isFirst(index: number): boolean {
return index === 0;
}
function isLast(index: number): boolean {
return index === tags.length - 1;
}
function addEmptyTag(): void { function addEmptyTag(): void {
if (tags[tags.length - 1].name.length === 0) { if (tags[tags.length - 1].name.length === 0) {
tags[tags.length - 1].active = true; tags[tags.length - 1].active = true;
@ -111,18 +119,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
async function moveToNextTag(index: number): Promise<void> { async function moveToNextTag(index: number): Promise<void> {
if (index === tags.length - 2) { if (isLast(index)) {
addEmptyTag();
return; return;
// TODO
} else if (index === tags.length - 1) {
tags[index].active = false;
tags = tags;
await tick();
/* focusNewInput(); */
} }
tags[index].active = false;
tags[index + 1].active = true; tags[index + 1].active = true;
tags = tags; tags = tags;
@ -143,31 +144,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let:destroyAutocomplete let:destroyAutocomplete
> >
{#each tags as tag, index (tag.id)} {#each tags as tag, index (tag.id)}
{#if index !== tags.length - 1} <Tag
<Tag bind:name={tag.name}
bind:name={tag.name} bind:active={tag.active}
bind:active={tag.active} bind:blink={tag.blink}
bind:blink={tag.blink} on:tagupdate={() => addTagAt(index)}
on:tagupdate={() => addTagAt(index)} on:tagadd={() => insertTagAt(index)}
on:tagadd={() => insertTagAt(index)} on:tagdelete={() => deleteTagAt(index)}
on:tagdelete={() => deleteTagAt(index)} on:tagjoinprevious={() => joinWithPreviousTag(index)}
on:tagjoinprevious={() => joinWithPreviousTag(index)} on:tagjoinnext={() => joinWithNextTag(index)}
on:tagjoinnext={() => joinWithNextTag(index)} on:tagmoveprevious={() => moveToPreviousTag(index)}
on:tagmoveprevious={() => moveToPreviousTag(index)} on:tagmovenext={() => moveToNextTag(index)}
on:tagmovenext={() => moveToNextTag(index)} />
/>
{:else}
<Tag
bind:name={tag.name}
bind:active={tag.active}
bind:blink={tag.blink}
on:tagupdate={() => addTagAt(index)}
on:tagadd={() => insertTagAt(index)}
on:tagjoinprevious={() => joinWithPreviousTag(index)}
on:tagmoveprevious={() => moveToPreviousTag(index)}
on:tagmovenext={() => moveToNextTag(index)}
/>
{/if}
{/each} {/each}
<div <div