Skip to content

How do I refresh the view after modifying node.attrs? #2244

Discussion options

You must be logged in to vote

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
})

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@SF-Simon
Comment options

@philippkuehn
Comment options

@SF-Simon
Comment options

@philippkuehn
Comment options

Answer selected by SF-Simon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants