Skip to content

Commit

Permalink
fix?: Ignore image data on clipboard (preferring rich text) when it a…
Browse files Browse the repository at this point in the history
…ppears to be coming from Microsoft Office
  • Loading branch information
idreyn committed Mar 12, 2021
1 parent 90814cb commit 2f93327
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/components/Editor/plugins/paste/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ const getMediaUploadFromClipboard = (
return null;
};

const appearsToBePastingFromMsOffice = (event: ClipboardEvent) => {
const html = event.clipboardData?.getData('text/html');
return html && html.includes(`xmlns:o="urn:schemas-microsoft-com:office:office`);
};

export const createPasteHandler = (uploadFn: MediaUploadHandler) => (
view: EditorView,
event: ClipboardEvent,
) => {
if (appearsToBePastingFromMsOffice(event)) {
return false;
}
const selection = view.state.selection;
const clipboardItems = event.clipboardData?.items;
const upload = getMediaUploadFromClipboard(uploadFn, clipboardItems || null);
Expand Down

0 comments on commit 2f93327

Please sign in to comment.