diff --git a/ts/editor/Tag.svelte b/ts/editor/Tag.svelte index d896f9e77..1ca4b1fba 100644 --- a/ts/editor/Tag.svelte +++ b/ts/editor/Tag.svelte @@ -30,6 +30,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html if (name.length === 0) { deleteTag(event); + } else { + dispatch("tagupdate"); + event.stopPropagation(); } } diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index 26c84ca48..0623e5c1b 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -15,11 +15,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html let newInput: HTMLInputElement; let newName: string = ""; - function focusInputNew(): void { + function focusNewInput(): void { newInput.focus(); } - const insertTagAt = (index: number) => () => { + function checkForDuplicateAt(index: number): void { + const names = tags.map(getName); + const nameToUpdateTo = names.splice(index, 1)[0]; + + if (names.includes(nameToUpdateTo)) { + deleteTagAt(index); + } + } + + function insertTagAt(index: number): void { const names = tags.map(getName); const nameToInsert = names.splice(index, 1)[0]; @@ -29,12 +38,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html tags.splice(index, 0, attachId(nameToInsert)); tags = tags; - }; + } - const deleteTagAt = (index: number) => () => { + function deleteTagAt(index: number): void { tags.splice(index, 1); tags = tags; - }; + } function appendTag(): void { const names = tags.map(getName); @@ -49,13 +58,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
- + {#each tags as tag, index (tag.id)} checkForDuplicateAt(index)} + on:tagadd={() => insertTagAt(index)} + on:tagdelete={() => deleteTagAt(index)} /> {/each}