@marijn in this post you seem to suggest that the content should be used to get a node and find its absolute position in the doc:
So I tried traversing the document nodes from the view:
for (const child of view.docView.children) {
if (child.node.content === someStateNode.content) return child.posAtStart;
}
Obviously this doesn’t work.
Is there some util function in ProseMirror to compare content of nodes?
If comparing the content is not the right approach, then what would be?
Edit:
Since this content thing seemed pretty inefficient and hackish I found I can actually get the absolute document position of a cursor with $someCursor.parentOffset.
So now the trick is to actually create a cursor that falls on the node in question. In my case I could simply use findCutBefore($cursor) which would put the cursor at the end of the previous node and then substract the nodeSize from that.
Here is the full solution:
let $beforeCursor = findCutBefore($cursor);
const pos = $beforeCursor.parentOffset - $beforeCursor.nodeBefore.nodeSize;
dispatch(state.tr.setSelection(TextSelection.create(state.doc, pos)));
This does the trick, at least in my use case.