While playing with ProseMirror I had implemented a custom paragraph
node. My target is to show a menu specific to node type whenever a node receives the cursor: setSelection(anchor, head, root)
does indeed get called, but implementing this method results in dancing cursor whenever a mark is applied to any range of text of that node.
NOTE: I am well aware that contentEditable
doesn’t allow node’s to have focus so onFocus
event is not an option here.
class ParagraphView {
constructor(node$, view$, getPos$) {
this.dom = this.contentDOM = document.createElement("p");
this.viewState = view$.state;
if (node$.content.size == 0)
this.dom.classList.add("empty")
console.log(`${node$.type} has position ${getPos$()}`);
}
update(node$, decorations$) {
if (node$.type.name != "paragraph") return false
if (node$.content.size > 0) this.dom.classList.remove("p-empty")
else this.dom.classList.add("p-empty")
return true
}
setSelection(anchor$, head$, root$)
{
console.log("lets show a menu as soon as it is called on any curosor changes");
}
}
export default ParagraphView;