fix: Document title allows pasting rich text, closes #3079

This commit is contained in:
Tom Moor
2022-02-08 22:07:53 -08:00
parent 342bec5211
commit bc2556d004

View File

@@ -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<HTMLSpanElement>) => {
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…")