microsoft / microsoft/monaco-editor

Get/Restore Monaco editor Undo&Redo stack

Open
#686 24 comments 35 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

editor-core feature-request
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the editorInstance methods named in the report: getModel(), saveViewState(), dispose(), create(), setModel(), and restoreViewState(). Determine whether the Undo&Redo stack can be serialized and restored across disposal; done means the stack survives recreation without retaining the original model in memory.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.