Get/Restore Monaco editor Undo&Redo stack

See original GitHub issue

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? (Serialize it)


UPDATE: The model records edits in its own structure. However, we don’t have a direct access through its API. The next example seems to work but it keeps everything in memory. I would like to have a way where I could serialize it.

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);

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:25
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
acaocommented, Dec 16, 2021

@alexdima would you all be interested in a PR to introduce a public API for this? If so, do you have any design notes, constraints, existing or new ideas to share, etc?

CC @rebornix

8reactions
fabiospampinatocommented, Apr 1, 2021

@alexdima I tried porting the logic to the new system but it’s unclear to me where the actual data is stored. What should people do now to serialize the undo stack on disk for example? IMHO this kind of functionality is fairly critical and there should be some high-level APIs for this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to do Undo in monaco editor - Stack Overflow
So the issue is that after changing the coding language the previous code is not restored by pressing ctrl+z. Please help me solve...
Read more >
A brand new website interface for an even better experience!
Get/Restore Monaco editor Undo&Redo stack. ... Login using; GitHub; Twitter; Facebook; Email Address. Coming soon: A brand new website interface for an even ......
Read more >
Monaco Editor Undo Redo Samples
Monaco Editor Undo Redo Samples. Undo Redo. 1. 2. 3. function x() {. console.log("Hello world!");. } function x() { console.log("Hello world!"); }
Read more >
@monaco-editor/react - npm
@monaco-editor/react · monthly downloads gitHub license npm version PRs welcome ... text selection, undo stack, scroll position, etc.
Read more >
Building a code editor with Monaco - Expo Blog
Preserving undo/redo stack · On start, create new models for each file: monaco.editor. · When a file is opened, set the editor's model...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found