From 428655a32f7dc27e04c1a5eabf15b88d4e63948a Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sat, 26 Jun 2021 01:30:51 +0200 Subject: [PATCH] Almost implement tagmove * tagmovenext will start on the last position rather than first --- ts/editor/Tag.svelte | 7 ++++++- ts/editor/TagEditor.svelte | 36 ++++++++++++++++++++---------------- ts/editor/tags.ts | 3 ++- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ts/editor/Tag.svelte b/ts/editor/Tag.svelte index 145a6b586..9d896b320 100644 --- a/ts/editor/Tag.svelte +++ b/ts/editor/Tag.svelte @@ -9,10 +9,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { deleteIcon } from "./icons"; export let name: string; + export let active: boolean; const dispatch = createEventDispatcher(); - let active = false; let input: HTMLInputElement; function checkForActivation(): void { @@ -75,5 +75,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html button { padding: 0; + + &:focus, + &:active { + outline: none; + } } diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index f980a5d3b..2c439985d 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -22,11 +22,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html let newName: string = ""; function focusNewInput(): void { - if (document.activeElement === newInput) { - // refocus - newInput.blur(); - } - newInput.focus(); } @@ -81,26 +76,33 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html return; } - const before = tags.splice(index - 1, 1)[0]; - tags.splice(index, 0, before); + tags[index - 1].active = true; + tags[index].active = false; tags = tags; } function moveToNextTag(index: number): void { if (index === tags.length - 1 || tags.length === 1) { - return; + focusNewInput(); } - // TODO + + tags[index].active = false; + tags[index + 1].active = true; + tags = tags; } - function appendTag(): void { + function appendTag(): boolean { const names = tags.map(getName); + let added = false; + if (!names.includes(newName) && newName.length > 0) { tags.push(attachId(newName)); - tags = tags; + added = true; } + tags = tags; newName = ""; + return added; } function joinWithLastTag(): void { @@ -113,7 +115,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } function moveToLastTag(): void { - appendTag(); + const newTag = appendTag() ? tags[tags.length - 2] : tags[tags.length - 1]; + newTag.active = true; } @@ -131,8 +134,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {#each tags as tag, index (tag.id)} {}} + on:blur={() => {}} on:tagupdate={() => checkForDuplicateAt(index)} on:tagadd={() => insertTagAt(index)} on:tagdelete={() => deleteTagAt(index)} @@ -146,8 +150,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {}} + on:blur={() => {}} on:tagupdate={appendTag} on:tagadd={appendTag} on:tagjoinprevious={joinWithLastTag} diff --git a/ts/editor/tags.ts b/ts/editor/tags.ts index 620dce669..f9cb79dbe 100644 --- a/ts/editor/tags.ts +++ b/ts/editor/tags.ts @@ -17,11 +17,12 @@ export function normalizeTagname(tagname: string): string { interface Tag { name: string; + active: boolean; id: string; } export function attachId(name: string): Tag { - return { name, id: Math.random().toString(36).substring(2) }; + return { name, active: false, id: Math.random().toString(36).substring(2) }; } export function getName(tag: Tag): string {