I’m trying to trigger update()
on a NodeView
using a Decoration
but I can’t seem to get it to fire. The use-case here is just adding a number to each heading - kind of like the footnote example but we can’t use css to do it for our purposes.
This code generates the decorations. It’s enclosed in a function that is passed into our EditorView
constructor and as a result, is being called every time the document changes.
state.doc.descendants((testNode, pos, parent) => {
if (testNode.type === schema.nodes.sectionNumber) {
const spec = {
sectionNumber: counter
};
decos.push(
Decoration.node(
pos,
pos + testNode.nodeSize,
{ style: "color: #ff0000" },
spec
)
);
counter += 1;
}
return true;
});
I threw the { style:
color: #ff0000 }
in there just to make sure it was grabbing the correct node. Sure enough, the content (which is added via the dom
property in our NodeView
constructor) is colored red and the resulting HTML looks correct.
If I select the node and press spacebar, that space gets inserted as a text
node as a child of the sectionNumber
node and update()
IS called. When that happens, the Decoration
is passed into update()
and has the spec
populated as-expected. However, other changes to the document do not trigger an update()
.
Anyone have a guess as to what’s going wrong? My understanding was that update()
should be called because a new Decoration
is being constructed and added anytime the document changes.