From dbd6ac80800a5b665dc27cc5e558dfaed486458e Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 27 Nov 2024 11:25:54 -0800 Subject: [PATCH] refac: textarea --- src/lib/components/common/Textarea.svelte | 45 +++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/lib/components/common/Textarea.svelte b/src/lib/components/common/Textarea.svelte index 4c18ae195..254db2e4b 100644 --- a/src/lib/components/common/Textarea.svelte +++ b/src/lib/components/common/Textarea.svelte @@ -10,18 +10,49 @@ let textareaElement; + $: if (textareaElement) { + if (textareaElement.innerText !== value) { + textareaElement.innerText = value; + } + } + // Adjust height on mount and after setting the element. onMount(async () => { await tick(); }); + + // Handle paste event to ensure only plaintext is pasted + function handlePaste(event: ClipboardEvent) { + event.preventDefault(); // Prevent the default paste action + const clipboardData = event.clipboardData?.getData('text/plain'); // Get plaintext from clipboard + document.execCommand('insertText', false, clipboardData); // Insert plaintext into contenteditable + } -