ProseMirror / prosemirror

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

posAtCoords returns wrong position on inline decoration #1394

Closed nono1013 closed 1 year ago

nono1013 commented 1 year ago
  1. Setup a plugin that adds inline decorations, and add code that prints value from view.posAtCoords
  2. On inline decoration it returns the start or end position of dom node instead of the actual position (it works without decorations).

See https://github.com/nono1013/pm-deco-issue/blob/main/src/main.ts for example.

While debugging I found that posAtCoords goes into posFromCaret fn, where dom.nodeType == 1 since this is a span element, and isBlock will be false, and desc has no contentDom. As I understand the execution should not go into the if this is a text or a text inside inline decoration, but since !desc.contentDom will be true, the condition results in true (If I write it as if (desc.dom.nodeType == 1 && desc.node.isBlock && (desc.parent && !sawBlock || !desc.contentDOM)) { then I get correct results, though it's etirely possible that I'm misunderstanding the code, and this will result in something bad.)

marijnh commented 1 year ago

Attached patch should solve this.