ProseMirror / prosemirror

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

Editing an image removes parent link #1380

Closed nstoychev closed 1 year ago

nstoychev commented 1 year ago

Steps to Reproduce:

  1. Navigate to: https://prosemirror.net/examples/basic/
  2. Select the smiley face image in the editor and add a link around it.
  3. Select the image, open the "Insert Image" tool and add some title
  4. Inspect the image in the editor, you should see the the link is no longer there.

Expected behavior: The image should retain any hyperlinks that have been added.

Reproducible on Windows 10, Chrome and Firefox

marijnh commented 1 year ago

That's a command from the prosemirror-example-setup package, not the core library. Feel free to use a more clever command in your own setup if you want, but this doesn't seem like a big issue (the menu item is called "insert image", after all).

nstoychev commented 1 year ago

It is strange that the issue happens with link mark only, and works as expected with strong or em marks.

I'll use transaction.setNodeMarkup to update the image.

Thanks

marijnh commented 1 year ago

It is going through replaceSelectionWith, which will behave the same as typing with that selection—an inclusive mark, if entirely selected, will be preserved. But a non-inclusive mark (which links are) won't.