Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Pasting text from MS Word inserts as image in MDXEditor #641

Closed
MishaMgla opened this issue Nov 25, 2024 · 6 comments
Closed

[BUG] Pasting text from MS Word inserts as image in MDXEditor #641

MishaMgla opened this issue Nov 25, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@MishaMgla
Copy link
Contributor

Issue Description

When copying content from MS Word for Mac OS and pasting it into MDXEditor, the content is inserted as an image instead of editable text.

Steps to Reproduce

  1. Copy formatted text from MS Word for Mac OS.
  2. Paste into MDXEditor. https://mdxeditor.dev/editor/demo
  3. Observe that the content is inserted as an image.

Clipboard Data Formats

After copying content from MS Word, I ran osascript -e 'clipboard info' and received the following output:
«class RTF », 43042 «class ut16», 814 «class HTML», 40872 Unicode text, 820 «class PDF », 46178 «class weba», 41178 «class rtfd», 1956 «class utf8», 410 string, 0

Analysis

  • The clipboard contains multiple text formats (RTF, HTML, Unicode text, UTF-8) and non-text formats (PDF, RTFD, Web Archive).
  • RTFD and PDF formats may include images or render the content as a single non-editable object.
  • It appears MDXEditor is prioritizing one of the non-text formats when pasting, resulting in the content being inserted as an image.

Expected Behavior

MDXEditor should paste the text content with proper formatting, using one of the text-based formats like RTF or HTML.

Actual Behavior

The editor inserts the content as an image, making the text non-editable.

Environment

  • MS Word Version: Microsoft Word for Mac Version 16.91
  • Mac OS Version: macOS 15.1.1
  • Browser: Chrome Version 131.0.6778.86
  • MDXEditor Version: 3.19.0

Additional Information

  • I am willing to assist with further implementation and testing. I will be glad when someone suggests a starting point for researching the codebase.
@MishaMgla MishaMgla added the bug Something isn't working label Nov 25, 2024
@maltesa
Copy link
Contributor

maltesa commented Dec 4, 2024

I can confirm this issue. We are using MDXEditor in production at fiete.ai. Our users are reporting this issue frequently, since they are teachers who are using MS Word a lot.

Here is a short Video demonstrating the issue:
https://github.com/user-attachments/assets/5377beee-a777-422f-88a6-394d67213b66

In our app, where we have an upload handler implemented, the uploaded image contains the copied text.

@petyosi
Copy link
Contributor

petyosi commented Dec 4, 2024

@maltesa it's great that your company relies on this project. If it brings value to your business, you can either
contribute to it or sponsor its development and ongoing maintenance.

@maltesa
Copy link
Contributor

maltesa commented Dec 4, 2024

@petyosi I was about to update my comment, because I was looking into the code to find a fix by myself. I will also consider the sponsorship.

This is the content of the clipboard item when text is pasted from office:
image

What is the expected behaviour?
I think a clipboard item should only be pasted as image, if the item contains no text representation.

If you agree with this, I'm happy to open a pull-request for that. I hope this only requires a small change here:

cbPayload = cbPayload.filter((i) => i.type.includes('image')) // Strip out the non-image bits

@petyosi
Copy link
Contributor

petyosi commented Dec 4, 2024

I think a clipboard item should only be pasted as image, if the item contains no text representation.

That makes sense to me.

@maltesa
Copy link
Contributor

maltesa commented Dec 5, 2024

#652 should fix this.

@petyosi
Copy link
Contributor

petyosi commented Dec 5, 2024

Merged #652

@petyosi petyosi closed this as completed Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants