I’m trying to find a node in the current selection that has a given mark and select it in the editor.
For this, I start by obtaining the node position with doc.nodesBetween. I exptected to be able to select the node with the mark with NodeSelection. However, when I create it with $pos = tr.doc.resolve(pos) and new NodeSelection($pos), I always receive an exception: Uncaught TypeError: this.nodeDOM.classList is undefined.
Strangely, when I add 1 to the position I get from doc.nodesBetween, the selection is applied - but not on its first character ($pos = tr.doc.resolve(pos + 1) ):
How can I make sure the entire node is selected instead? Am I missing something?
Unfortunately this results in exactly the same behavior: tr.setSelection(NodeSelection.create(tr.doc, pos)) throws the Uncaught TypeError: this.nodeDOM.classList is undefined error while tr.setSelection(NodeSelection.create(tr.doc, pos + 1)) selects the node except for its first character.
I’ve remixed the sample project here with a button that does what my code above does:
As you can see, it triggers the same error from ProseMirror (it goes away if you change pos to pos + 1 though strangely the selection doesn’t actually change then)