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

windows: Implement copy/paste images #17852

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

JunkuiZhang
Copy link
Contributor

@JunkuiZhang JunkuiZhang commented Sep 15, 2024

Clipboard Behavior on Windows Under This PR:

User Action Zed’s Behavior
Paste PNG Worked
Paste JPEG Worked
Paste WebP Worked, but not in the way you expect (see Issue section below)
Paste GIF Partially worked (see Issue section below)
Paste SVG Partially worked (see Issue section below)
Paste BMP Worked, but not in the way you expect (see Issue section below)
Paste TIFF Worked, but not in the way you expect (see Issue section below)
Paste Files Worked, same behavior as macOS
Copy image in Zed Not tested, as I couldn’t find a way to copy images

Differences Between the Windows and macOS Clipboard

The clipboard functionality on Windows differs significantly from macOS. On macOS, there can be multiple items in the clipboard, whereas, on Windows, the clipboard holds only a single item. You can retrieve different formats from the clipboard, but they are all just different representations of the same item.

For example, when you copy a JPG image from Microsoft Word, the clipboard will contain data in several formats:

  • Microsoft Office proprietary data
  • JPG format data
  • PNG format data
  • SVG format data

Please note that these formats all represent the same image, just in different formats. This is due to compatibility concerns on Windows, as various applications support different formats. Ideally, multiple formats should be placed on the clipboard to support more software. However, in general, supporting PNG will cover 99% of software, like Chrome, which only supports PNG and BMP formats.

Additionally, since the clipboard on Windows only contains a single item, special handling is required when copying multiple objects, such as text and images. For instance, if you copy both text and an image simultaneously in Microsoft Word, Microsoft places the following data on the clipboard:

  • Microsoft Office proprietary data containing a lot of content such as text fonts, sizes, italics, positioning, image size, content, etc.
  • RTF data representing the above content in RTF format
  • HTML data representing the content in HTML format
  • Plain text data

Therefore, for the current ClipboardItem implementation, if there are multiple ClipboardEntry objects to be placed on the clipboard, RTF or HTML formats are required. This PR does not support this scenario, and only supports copying or pasting a single item from the clipboard.


Known Issues

  • WebP, BMP, TIFF: These formats are not explicitly supported in this PR. However, as mentioned earlier, in most cases, there are corresponding PNG format data on the clipboard. This PR retrieves data via PNG format, so users copying images in these formats from other sources will still see the images displayed correctly.

  • GIF: In this PR, GIFs are displayed, but for GIF images with multiple frames, the image will not animate and will freeze on a single frame. Since I observed the same behavior on macOS, I believe this is not an issue with this PR.

  • SVG: In this PR, only the top-left corner of the SVG image is displayed. Again, I observed the same behavior on macOS, so I believe this issue is not specific to this PR.


I hope this provides a clearer understanding. Any feedback or suggestions on how to improve this are welcome.

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Sep 15, 2024
@MatinAniss
Copy link
Contributor

The reason why a GIF does not animate is most likely because the img element does not have an element id to allow it to animate across frames.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants