From 9ea606a734cefdd3d725914b4301428ec2e2937a Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 25 Jan 2023 22:37:47 -0500 Subject: [PATCH] fix: Pasting from Microsoft Office pastes image. Closes #3058 --- shared/editor/nodes/Image.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/shared/editor/nodes/Image.tsx b/shared/editor/nodes/Image.tsx index 655ca7f14..5ea848993 100644 --- a/shared/editor/nodes/Image.tsx +++ b/shared/editor/nodes/Image.tsx @@ -59,6 +59,19 @@ const uploadPlugin = (options: Options) => return false; } + // When copying from Microsoft Office product the clipboard contains + // an image version of the content, check if there is also text and + // use that instead in this scenario. + const html = event.clipboardData.getData("text/html"); + const text = event.clipboardData.getData("text/plain"); + const isMicrosoftOffice = html.includes( + "urn:schemas-microsoft-com:office" + ); + if (text.length && isMicrosoftOffice) { + // Fallback to default paste behavior + return false; + } + const { tr } = view.state; if (!tr.selection.empty) { tr.deleteSelection();