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

Handle paste with text and images, preferring text #438

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

humphd
Copy link
Collaborator

@humphd humphd commented Feb 12, 2024

My daughter ran into an interesting bug with our new image handling:

  • copy text from an MS Word document
  • paste into ChatCraft
  • notice an image is added vs. text

In researching what is happening here, I learned that when you copy text in MS Word, it puts 4 things on the clipboard (i.e., 4 representations of the same text):

  • text/plain
  • text/html
  • text/rtf
  • image/png

The final image/png is a bitmap of the formatted text. I guess the idea is to try to maintain the formatting on the text, even if it has to be rendered into an image!

The result is that it's impossible to paste text when there's an image representation also in the same clipboard data.

I've updated our paste handling for the prompt form so that it prefers text if the text is available. If you copy an image, we'll only have the image, so that will get used.

I've also added e.preventDefault() to the image handling case so that we use our custom handler; however, in the case of text, we let it fall through and do the default thing (e.g. pasting the text).

@humphd humphd added the bug Something isn't working label Feb 12, 2024
@humphd humphd added this to the Release 1.3 milestone Feb 12, 2024
@humphd humphd self-assigned this Feb 12, 2024
Copy link
Collaborator

@mingming-ma mingming-ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I've gained a good understanding of this copy&paste scenario related to MS Office apps.

@humphd humphd merged commit 11aa6dd into main Feb 14, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants