Programmatically clear the content?

I’d like to programmatically replace the content with a new one.

For now I’m using insert:

editorView.current.dispatch({
      changes: { from: 0, insert: value },
    })

But I’d like to replace the old content with the new one. I couldn’t find what to call.

You should usually just create a new state and use setState to reset the view to that. But if you really want to replace the content, keeping the old undo history and such intact, pass {from: 0, to: editorView.current.state.doc.length, insert: value} under changes.

1 Like