From 3de1d6e604c110f95b64992cb1c2a56bc715c064 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Thu, 8 Jul 2021 21:25:01 +0200 Subject: [PATCH] Use Unicode delimiter character --- ts/editor/TagEditor.svelte | 24 +++++++++++++------ ts/editor/TagInput.svelte | 48 +++++++++++++++----------------------- ts/editor/tags.ts | 14 +++++++++-- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index da1488701..646e25889 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -16,18 +16,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import ButtonToolbar from "components/ButtonToolbar.svelte"; import { controlPressed } from "lib/keys"; import type { Tag as TagType } from "./tags"; - import { attachId, getName } from "./tags"; + import { + attachId, + getName, + delimChar, + replaceWithDelimChar, + replaceWithColon, + } from "./tags"; export let size = isApplePlatform() ? 1.6 : 2.0; export let tags: TagType[] = []; export function resetTags(names: string[]): void { - tags = names.map(attachId); + tags = names.map(replaceWithDelimChar).map(attachId); } function saveTags(): void { - bridgeCommand(`saveTags:${JSON.stringify(tags.map((tag) => tag.name))}`); + bridgeCommand( + `saveTags:${JSON.stringify( + tags.map((tag) => tag.name).map(replaceWithColon) + )}` + ); } let active: number | null = null; @@ -43,7 +53,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html "en::vocabulary", "en::idioms", Math.random().toString(36).substring(2), - ]); + ]).then((names: string[]): string[] => names.map(replaceWithDelimChar)); } function onAutocomplete(selected: string): void { @@ -369,17 +379,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html $: shortenTags = shortenTags || assumedRows > 2; function processTagName(name: string): string { - const parts = name.split("::"); + const parts = name.split(delimChar); if (parts.length === 1) { return name; } - return "…::" + parts[parts.length - 1]; + return `…${delimChar}` + parts[parts.length - 1]; } function hasMultipleParts(name: string): boolean { - return name.split("::").length > 1; + return name.split(delimChar).length > 1; } diff --git a/ts/editor/TagInput.svelte b/ts/editor/TagInput.svelte index f3246ce2a..f5ec27cd7 100644 --- a/ts/editor/TagInput.svelte +++ b/ts/editor/TagInput.svelte @@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -->