How do I refresh the view after modifying node.attrs? #2244
Answered
by
philippkuehn
SF-Simon
asked this question in
Questions & Help
-
We need to update the nodes mentioned. Therefore, we find all the nodes, and then modify the
|
Beta Was this translation helpful? Give feedback.
Answered by
philippkuehn
Dec 7, 2021
Replies: 1 comment 4 replies
-
nodes are immutable. You have to use transactions to update the state. Something like this should work editor.state.doc.descendants((node, position) => {
if (node.attrs.id === 'custom') {
const tr = editor.state.tr
tr.setNodeMarkup(pos, undefined, {
...node.attrs,
{ label: 'New label' },
})
editor.view.dispatch(tr)
}
}) You can also use an inline command for it. editor.commands.command(({ tr }) => {
tr.doc.descendants((node, position) => {
if (node.attrs.id === 'custom') {
tr.setNodeMarkup(pos, undefined, {
...node.attrs,
{ label: 'New label' },
})
}
})
return true
}) |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
SF-Simon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nodes are immutable. You have to use transactions to update the state. Something like this should work
You can also use an inline command for it.