Example of onchange for CodeMirror6?

I could not figure out which API(s) in view/state to listen on state.doc change.

I think this is the closest equivalent to CM5’s change event:

let updateListenerExtension = EditorView.updateListener.of((update) => {
  if (update.docChanged) {
    // Handle the event here
  }
});

let state = EditorState.create({
    extensions: [updateListenerExtension/* Add your other extensions */]
});
1 Like