How to undo on button press?

After reading the documentation I’m not sure how to call the undo history function programmatically, for example on a button press. Thank you!

You can do…

import {undo} from "@codemirror/history"

myButton.onmousedown = e => {
  undo(view)
  e.preventDefault()
}
2 Likes

Thank you very much!

If I do this in my app I get an error:

Uncaught RangeError: Trying to update state with a transaction that doesn't start from the previous state.
    at EditorView.update (index.js:5850:23)
    at EditorView._dispatch (index.js:5776:59)
    at EditorView.dispatch (index.js:5832:14)
    at index.js:109:9
    at Proxy.undo (CodeMirror.vue:368:7)

If I hit ctrl+z everything works fine. Any idea about this? Thank you!

No. Can you show this happening in an isolated minimal script?