Skip to content

Add text/uri-list support in clipboard. - #4478

Merged
zurfyx merged 2 commits into
meta:mainfrom
xinyuan0801:support-text-uri-list-paste
May 10, 2023
Merged

zurfyx merged 2 commits into
meta:mainfrom
xinyuan0801:support-text-uri-list-paste

Conversation

@xinyuan0801

@xinyuan0801 xinyuan0801 commented May 10, 2023 •

Copy link
Copy Markdown

Background

Issue #4409 highlights a problem where users are unable to paste text/uri-list type content. This PR aims to address and resolve this issue.

Cause of the Problem

The problem is due to discrepancies in the valid MIME types for read/write operations in the clipboard between Chromium and WebKit.

Chromium supports the read/write operations for the following MIME types (Chromium):

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

On the other hand, WebKit supports all the above types as well as text/uri-list (WebKit).

This inconsistency causes an issue when, for example, a user opens a webpage in Safari on iOS, copies content via the share menu, and tries to paste it elsewhere. In this case, the MIME type of the content in the clipboard is text/uri-list.

However, based on the current logic in $insertDataTransferForRichText in clipboard.ts, only text/plain, text/html, image/png, and 'application/x-lexical-editor' are accepted for pasting. Hence, when a user attempts to paste text of type text/uri-list, no content is pasted.

Proposed Changes

This PR proposes a modification to the $insertDataTransferForRichText function in clipboard.ts to support pasting of text/uri-list MIME type.

Impact of Changes

This change will allow pasting of text/uri-list type content in Safari. However, given Chrome's current lack of support for reading/writing text/uri-list in the clipboard, the behaviour of pasting this MIME type in Chrome remains unchanged.

Fixes #4409

@vercel

vercel Bot commented May 10, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2023 3:13pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2023 3:13pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 10, 2023

@zurfyx zurfyx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you! But I'd be curious to know more about the use case. I wasn't able to repro this from my LinkedIn app, Pasteboard shows type public.url and it isn't retrievable via text/uri-list

You also need to update $insertDataTransferForPlainText for plain text users support

@@ -130,22 +130,35 @@ export function $insertDataTransferForRichText(
// instead of single paragraph with linebreaks.
const text = dataTransfer.getData('text/plain');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given that we're doing a nullish check below you can just do this

Suggested change
const text = dataTransfer.getData('text/plain');
const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you, this has been fixed in the newest commit and i have also apply the changes to plain text paste.

@xinyuan0801

Copy link
Copy Markdown
Author

LGTM, thank you! But I'd be curious to know more about the use case. I wasn't able to repro this from my LinkedIn app, Pasteboard shows type public.url and it isn't retrievable via text/uri-list

You also need to update $insertDataTransferForPlainText for plain text users support

Hi, i believe this has something to do with the copy operation in the share pop-up menu in IOS. i am able to reproduce by using the copy in share pop-up menu of Safari, Linkedin and instagram in IOS.

Below is the screen recording of the repro in Safari and Linkedin app

RPReplay_Final1683728447.1.mp4
RPReplay_Final1683728291.1.mp4

Sorry my phone's language is Chinese so it might be not so clear, but what i did is just use the copy from ios share pop-up menu and paste it in lexical playground. you can see from the log that there is a Clipboard Event but nothing is pasted. This also happens in instagram when trying to share in the same way and I believe it happens as long as user are using the copy operation provided by IOS native share pop-up menu.

After the fix, it was able to paste the content from clipboard that are from the share menu pop-up.

RPReplay_Final1683729504.MP4

@zurfyx zurfyx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the videos, appreciate it!

@zurfyx
zurfyx merged commit 634a94a into meta:main May 10, 2023
This was referenced May 23, 2023

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — f621614f Deployed May 10, 2023 by vercel[bot]
Preview – lexical — f621614f Deployed May 10, 2023 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Support for text/uri-list type when pasting

4 participants