Skip to content

🐛 use imageFlavor instead of javaFileListFlavor for single-image clipboard writes#4302

Merged
guiyanakuang merged 2 commits intoCrossPaste:mainfrom
Fldicoahkiin:fix/image-paste-use-image-flavor
Apr 26, 2026
Merged

🐛 use imageFlavor instead of javaFileListFlavor for single-image clipboard writes#4302
guiyanakuang merged 2 commits intoCrossPaste:mainfrom
Fldicoahkiin:fix/image-paste-use-image-flavor

Conversation

@Fldicoahkiin
Copy link
Copy Markdown
Contributor

@Fldicoahkiin Fldicoahkiin commented Apr 26, 2026

Summary

Fixes #2729

When pasting a single image from CrossPaste history (right-click copy or double-click quick paste), apps like WeChat and Notes on macOS receive a file:/// path instead of the actual image. This is because DesktopImageTypePlugin.buildTransferable() places javaFileListFlavor (file list) on the clipboard, which macOS translates to public.file-url pasteboard entries. Apps that prefer text/URL types over image types end up pasting the file path.

This PR changes single-image clipboard writes to use imageFlavor (BufferedImage) as the primary clipboard data, matching the behavior of native macOS screenshot paste (public.tiff). Falls back to javaFileListFlavor only when the image cannot be read. Multi-image clipboard writes remain unchanged.

Changes

  • For single images: place imageFlavor (BufferedImage) on the clipboard instead of javaFileListFlavor
  • Fall back to javaFileListFlavor when imageHandler.readImage() returns null or throws
  • Multi-image behavior unchanged (still uses javaFileListFlavor)

Test plan

  • Take a screenshot on macOS, copy from CrossPaste history, paste into WeChat — image pastes correctly
  • Take a screenshot on macOS, copy from CrossPaste history, paste into Notes — image pastes correctly
  • Verify multi-image paste still works as file list
  • Verify drag-and-drop from side panel still works
  • Verify on Windows and Linux that existing behavior is preserved

…board writes

For single images, place BufferedImage (imageFlavor) on the clipboard
instead of file list references. On macOS, javaFileListFlavor produces
public.file-url pasteboard entries that apps like WeChat read as text,
resulting in file:/// paths being pasted instead of the actual image.

Fall back to javaFileListFlavor only when the image cannot be read.
Multi-image clipboard writes remain unchanged.
@guiyanakuang
Copy link
Copy Markdown
Member

Hi @Fldicoahkiin, thanks a lot for the PR and the careful diagnosis — #2729 is a real bug, and you've correctly identified that AWT translates javaFileListFlavor into public.file-url, which apps like WeChat and Notes prefer over the image flavor. Aiming for parity with native screenshot paste is a sensible direction.

I pulled the branch locally to test and unfortunately found a regression we need to address before merging:

  • Pasting a single image into Finder no longer creates a file. Finder relies on javaFileListFlavor to materialize the paste. With the current PR, single-image clipboards only carry imageFlavor, so Finder has nothing to work with.
  • Drag-and-drop from CrossPaste's side panel onto Finder uses the same buildTransferable and is affected the same way.

So we still need to keep map[DataFlavor.javaFileListFlavor.toPasteDataFlavor()] = fileList in the single-image branch.

keep map[DataFlavor.javaFileListFlavor.toPasteDataFlavor()] = fileList in the single-image branch
@guiyanakuang guiyanakuang merged commit ffd8fbc into CrossPaste:main Apr 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screenshots are synchronized to another mac and then copied and cannot be pasted into the WeChat chat input box

2 participants