I want to create a system to store the Undo&Redo stack
of the Monaco editor.
Why?: I have a Monaco instance where I do several changes. Then I have to dispose that instance and open a new one. Here, I want to restore the same stack state that I had in the previous instance.
Question: How can I get and restore the Undo&Redo stack
?
UPDATE:
When I dispose the Monaco editor instance, the JavaScript environment can be completely destroyed. It is integrated in a C#
environment that is capable to communicate with JS
. My goal is to store the Monaco Editor model
in the C#
or serialize it.
It all has to do with the Model.
If you restore the same model you will have the Undo&Redo stacks
See Example
var model = editorInstance.getModel();
var viewState = editorInstance.saveViewState();
//Destroy your instance for whatever reason
editorInstance.dispose();
//When you create the new instance load the model that you saved
var newInstance = monaco.editor.create(elem, options);
newInstance.setModel(model);
newInstance.restoreViewState(viewState);
Something that might help would be to tie into the monaco event hook
monaco.editor.onWillDisposeModel(saveModel)
The viewState
can be used to resume the cursor position of the editor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With