I seen lot of topics here for the relatively same question and also tried to make sense of the documentation but I’m pretty lost
My use case is I need to decorate a specific node that I know the path (for instance the 1st paragraph from root) and I tried so many thing but I always getting out of range position.
There is my current experimentation:
const root = doc.child(0) // The very first child is a root node
const pNode = root.child(0) // For my test I have only one paragraph with one letter text
// None of the following works
decorations.push(Decoration.node(
pNode.resolve(0).pos,
pNode.resolve(pNode.nodeSize).pos,
{ class: 'decoration' }
))
const position = pNode.resolve(0)
decorations.push(Decoration.node(
position.before(),
position.after(),
{ class: 'decoration' }
))
// Now I just tried the following, no error but no class rendered :'(
const position = pNode.resolve(0)
decorations.push(Decoration.node(
position.pos,
position.pos + pNode.content.size,
{ class: 'decoration' }
))
// The plugin
new Plugin<{ decorations: DecorationSet | undefined }>({
key: pluginKey,
state: {
init: () => ({
decorations: undefined
}),
apply: (transaction, prev) => {
if (transaction.docChanged) {
return { decorations: DecorationSet.create(getDecorations()) }
}
return prev
}
},
props: {
decorations (state) {
console.info('this.getState(state).decorations', this.getState(state).decorations)
return this.getState(state).decorations
}
}
})
I’m sorry if my question looks dumb, I think I understand position indexing and what this implies but I do not get how I can have a correct node decoration here
Any help would be greatly appreciated and maybe some extra example in the documentation could be super helpful for anyone in the same situation.