From 70db792549352868b9017a559a61111c8cde8ec7 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sat, 1 Feb 2020 04:06:27 +0000 Subject: [PATCH] Allow copy pasting inside of wysiwyg element (#651) We did some hackery to prevent copy pasting when we didn't support multilines. But we do now so we can remove it. Interestingly, newlines are actually
elements. So we need to tweak the isInputLike logic a bit --- src/element/textWysiwyg.tsx | 9 --------- src/utils.ts | 1 + 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/element/textWysiwyg.tsx b/src/element/textWysiwyg.tsx index 584af1c6..d7056272 100644 --- a/src/element/textWysiwyg.tsx +++ b/src/element/textWysiwyg.tsx @@ -73,14 +73,6 @@ export function textWysiwyg({ } }; editable.onblur = handleSubmit; - // override paste to disallow non-textual data, and replace newlines - editable.onpaste = ev => { - ev.preventDefault(); - try { - const text = ev.clipboardData!.getData("text").replace(/\n+/g, " "); - editable.textContent = text; - } catch {} - }; function stopEvent(ev: Event) { ev.stopPropagation(); @@ -98,7 +90,6 @@ export function textWysiwyg({ function cleanup() { editable.onblur = null; editable.onkeydown = null; - editable.onpaste = null; window.removeEventListener("wheel", stopEvent, true); document.body.removeChild(editable); } diff --git a/src/utils.ts b/src/utils.ts index bcbbb6d4..2d5a0269 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -31,6 +31,7 @@ export function isInputLike( | HTMLDivElement { return ( (target instanceof HTMLElement && target.dataset.type === "wysiwyg") || + target instanceof HTMLBRElement || // newline in wysiwyg target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement