All this is connected with the model.
If you restore the same model, you will have stacks of Undo & Redo
See example
var model = editorInstance.getModel(); var viewState = editorInstance.saveViewState();
Something that could help was to hook the events in Monaco.
monaco.editor.onWillDisposeModel(saveModel)
viewState can be used to resume the cursor position in the editor.
source share