ProseMirror / prosemirror

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

posAtCoords / dropcursor in shadow root will jump to block end on Chrome #1367

Closed eric-burel closed 1 year ago

eric-burel commented 1 year ago

The editor is rendered within a web component shadow root.

On the screenshot you can see that if the dragged text is between 2 lines, the cursor (yellow) will jump at the end of the block.

This happens only on Chrome (Chromium 111.0.5563.64 (Build officiel) snap (64 bits) on Ubuntu) not Firefox. This doesn't happen in Prosemirror demo (https://glitch.com/edit/#!/remix/prosemirror-demo-basic) hence the strong suspicion that it comes from the Shadow Root.

This is visible while drag and dropping, however the root issue seems to be in "prosemirror-view" posAtCoords method, which returns a position at the end of the block. If I hover text and not blank space, the cursor is back to normal, leading to visual jumps during drag and unreliable drag and drop experience.

image

I've managed to build a repro: https://insidious-therapeutic-point.glitch.me/

marijnh commented 1 year ago

Chrome's caretRangeFromPoint is broken in shadow roots, and the editor's own replacement implementation didn't handle this situation well. Attached patch should help.

eric-burel commented 1 year ago

Thanks for the fast response!