Replace delim char with colons on copying tags

This commit is contained in:
Henrik Giesel 2021-07-09 02:17:21 +02:00
parent 46e607a777
commit 85691fada2
2 changed files with 11 additions and 2 deletions

View file

@ -350,7 +350,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
function copySelectedTags() { function copySelectedTags() {
const content = tags const content = tags
.filter((tag) => tag.selected) .filter((tag) => tag.selected)
.map((tag) => tag.name) .map((tag) => replaceWithColon(tag.name))
.join("\n"); .join("\n");
copyToClipboard(content); copyToClipboard(content);
deselect(); deselect();

View file

@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { onMount, createEventDispatcher, tick } from "svelte"; import { onMount, createEventDispatcher, tick } from "svelte";
import { normalizeTagname, delimChar } from "./tags"; import { normalizeTagname, delimChar, replaceWithColon } from "./tags";
export let id: string | undefined = undefined; export let id: string | undefined = undefined;
let className: string = ""; let className: string = "";
@ -178,6 +178,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
} }
function onCopy(event: ClipboardEvent): void {
const selection = document.getSelection();
event.clipboardData!.setData(
"text/plain",
replaceWithColon(selection!.toString())
);
}
function onPaste(event: ClipboardEvent): void { function onPaste(event: ClipboardEvent): void {
if (!event.clipboardData) { if (!event.clipboardData) {
return; return;
@ -220,6 +228,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:keydown on:keydown
on:keyup on:keyup
on:input on:input
on:copy|preventDefault={onCopy}
on:paste|preventDefault={onPaste} on:paste|preventDefault={onPaste}
/> />