ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.59k stars 335 forks source link

Pasting text inside of a link splits the link in two #1386

Closed ericandrewlewis closed 1 year ago

ericandrewlewis commented 1 year ago

Consider a document that has a link in it:

Hey Eric, here is the <a href="some-url">event I am going to</a>.

If you copy and paste plain text into the link, the link is split:

Hey Eric, here is the <a href="some-url">event </a> on Friday, Jun 8th<a href="some-url"> I am going to</a>.

This is unexpected to me. I'd expect the pasted plain text to become part of the link.

I believe the doPaste() method is related.

I notice this in Chrome on Mac, although would guess the behavior applies to other browsers as well.

You can reproduce this in the editor on the homepage.

marijnh commented 1 year ago

If you paste plain text (i.e. paste from the URL bar or Emacs) it seems to add the link mark to the pasted text.

If you paste html that holds just text, it keeps the markup (i.e. no link) from the pasted content.

Are you suggesting there should be some logic to recognize HTML that holds just text, and treat that as a text insertion rather than a paste of already-styled content? Or do you think context marks should always be added to pasted content? (Only inline content, or also pastes that span multiple blocks?)

ericandrewlewis commented 1 year ago

I think I confused myself. The existing behavior seems fine as-is, thanks for taking a look.