diff --git a/frontend/.editorconfig b/frontend/.editorconfig deleted file mode 100644 index 1f6746f..0000000 --- a/frontend/.editorconfig +++ /dev/null @@ -1,4 +0,0 @@ -[*] -tab_width = 2 -insert_final_newline = true -indent_style = space diff --git a/frontend/src/components/codeviewer.svelte b/frontend/src/components/codeviewer.svelte index c18549d..a538740 100644 --- a/frontend/src/components/codeviewer.svelte +++ b/frontend/src/components/codeviewer.svelte @@ -5,6 +5,7 @@ import Icon from './icon.svelte'; import Modal from './modal.svelte'; import 'highlight.js/styles/atom-one-dark.css'; + import { onDestroy } from 'svelte'; export let code = ''; export let language = 'json'; @@ -17,11 +18,17 @@ hljs.registerLanguage('json', hljsJSON); hljs.registerLanguage('js', hljsJavaScript); - $: highlighted = code ? hljs.highlight(language, code).value : ''; + let copySucceeded = false; + let timeout; + $: highlighted = code ? hljs.highlight(code, { language }).value : ''; - function copy() { - navigator.clipboard.writeText(code); + async function copy() { + await navigator.clipboard.writeText(code); + copySucceeded = true; + timeout = setTimeout(() => copySucceeded = false, 1500); } + + onDestroy(() => clearTimeout(timeout)); {#if code} @@ -29,7 +36,7 @@
{@html highlighted}