From bc2556d0045496b60227fd5f2607f48d7369a90d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 8 Feb 2022 22:07:53 -0800 Subject: [PATCH] fix: Document title allows pasting rich text, closes #3079 --- app/scenes/Document/components/EditableTitle.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/scenes/Document/components/EditableTitle.tsx b/app/scenes/Document/components/EditableTitle.tsx index e3b162423..9e078b762 100644 --- a/app/scenes/Document/components/EditableTitle.tsx +++ b/app/scenes/Document/components/EditableTitle.tsx @@ -52,6 +52,17 @@ const EditableTitle = React.forwardRef( ref.current?.focus(); }, [ref]); + // Ensure only plain text can be pasted into title when pasting from another + // rich text editor + const handlePaste = React.useCallback( + (event: React.ClipboardEvent) => { + event.preventDefault(); + const text = event.clipboardData.getData("text/plain"); + window.document.execCommand("insertText", false, text); + }, + [] + ); + const handleKeyDown = React.useCallback( (event: React.KeyboardEvent) => { if (event.key === "Enter") { @@ -119,6 +130,7 @@ const EditableTitle = React.forwardRef( onClick={handleClick} onChange={onChange} onKeyDown={handleKeyDown} + onPaste={handlePaste} placeholder={ document.isTemplate ? t("Start your template…")