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: Link decays into multiple links when pasting #1496

Closed
REPLicated opened this issue Nov 11, 2024 · 7 comments
Closed

Windows: Link decays into multiple links when pasting #1496

REPLicated opened this issue Nov 11, 2024 · 7 comments

Comments

@REPLicated
Copy link

In Edge on Windows, certain pasted links "decay" into two separate links, where one of them is invalid.

Windows is special because when copying the URL of an open tab, the clipboard content is structured (presumably HTML), where the link text is the title of the tab and the href the actual URL.

Example: When copying the link from a tab with title foo:bar.pdf and URL http://localhost/foobar, this results in the editor HTML

<p><a href="http://localhost/foobar">foo:</a><a href="bar.pdf" target="_blank">bar.pdf</a></p>
@marijnh
Copy link
Member

marijnh commented Nov 11, 2024

Is this an issue of ProseMirror incorrectly parsing the HTML from the clipboard, or the HTML not making sense in the first place? In the latter case, it may not be something the library can do much about.

@REPLicated
Copy link
Author

Without ProseMirror, I created a textarea and registered an event handler for ClipboardEvent. The HTML seems to be valid:

  onPaste(ev: ClipboardEvent): void {
    console.log("Pasting", ev.clipboardData?.getData("text/html"))
  }

Results in:

Pasting <html>
<body>
<!--StartFragment--><a href="http://localhost/foobar">foo:bar.pdf</a><!--EndFragment-->
</body>
</html>

@marijnh
Copy link
Member

marijnh commented Nov 11, 2024

Do you maybe have a custom paste handler in your editor? One that tries to detect and autolink urls? When I try to paste the HTML you show, I just get a regular, single link, as expected.

@REPLicated
Copy link
Author

REPLicated commented Nov 11, 2024

We use ProseMirror via https://sibiraj-s.github.io/ngx-editor/. And indeed, it has a plugin that linkifies pasted text:
https://github.com/sibiraj-s/ngx-editor/blob/master/projects/ngx-editor/src/lib/plugins/link.ts

I will investigate whether this is the cause.

@REPLicated
Copy link
Author

It seems that the HTML is first pasted, and then the transformPasted of the ngx-editor linkify plugin is called with the link text. Since its regex matching is not very strict, the link text "foo:bar.pdf" is recognized as a link and then pasted as a second link after the first one.

@sibiraj-s is this intended behavior?

@marijnh
Copy link
Member

marijnh commented Nov 11, 2024

Since the misbehavior doesn't seem to be in code I maintain, I'm going to close this issue here.

@marijnh marijnh closed this as completed Nov 11, 2024
@sibiraj-s
Copy link

Hi @REPLicated, I have to check, please create a issue in the editors repo and continue the discussion there.

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

No branches or pull requests

3 participants