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

pasting links from iOS share sheet #4060

Closed
mathonify opened this issue Mar 17, 2024 · 2 comments · Fixed by #4064
Closed

pasting links from iOS share sheet #4060

mathonify opened this issue Mar 17, 2024 · 2 comments · Fixed by #4064

Comments

@mathonify
Copy link

When pasting links from the iOS share sheet to the quill editor, nothing is pasted.
ezgif com-optimize-2

I saw a similar issue mentioned on the prose mirror discussion page. They solved this issue by making sure to capture "text/uri-list" from the clipboard. Not sure if it is the same problem, I will keep trying to debug to find the error. I am quite new to quill so it will take me some time to find the exact problem. Perhaps someone who understands quill better could find the solution faster.

@mathonify
Copy link
Author

mathonify commented Mar 17, 2024

this seems to fix the issue:

// Register an event listener for the paste event on the Quill editor
quill.root.addEventListener('paste', function(event) {
    // Get the clipboard data
    var clipboardData = event.clipboardData || window.clipboardData;
    if (!clipboardData) return;

    // Extract URI content from the clipboard data
    var uri = clipboardData.getData("text/uri-list");
    if (uri) {
        // Prevent default paste behavior
        event.preventDefault();

        // Insert URI as plain text at the current cursor position
        var range = quill.getSelection();
        quill.insertText(range.index, uri);
    }
});

edit: I noticed this causes the url to paste twice on macOS, so I added to check iOS:

quill.root.addEventListener('paste', function(event) {
    var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
    if (!isIOS) {
        return;
    }
    var clipboardData = event.clipboardData || window.clipboardData;
    if (!clipboardData) return;
    var uri = clipboardData.getData("text/uri-list");
    if (uri) {
        event.preventDefault();
        var range = quill.getSelection();
        quill.insertText(range.index, uri);
    }
});

@luin
Copy link
Member

luin commented Mar 19, 2024

Will be fixed in the next release. Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants