microsoft / microsoft/monaco-editor
Expose undo stops in API?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Monaco has a concept of "undo stops" but doesn't give a way to access it without actually invoking undo.
I instrumented the onDidChangeContent with:
const model = editor.getModel();
model.onDidChangeContent(() => {
console.log(model.getAlternativeVersionId());
});
And I can see that if I type "one two" then press undo, I see:
1 // o
2 // n
3 // e
4 // space
5 // t
6 // w
7 // o
3 // undo restores the text to "one"
So Monaco has decided to put an undo-stop in after version 3 based on some internal logic.
My wish: I'd like a field in IModelContentChangedEvent to indicate when an undo stop is created. eg.
model.onDidChangeContent(({isNewUndoStackElement}) => {
// In the above example, isNewUndoStackElement would be true on the 1st and 4th call
});
The reason I want this is so I can integrate this into the broader undo stack of the document in which the monaco editor is embedded. eg. my document would have many monaco editors and when the user invokes undo, it would pick which of the monacos to send that undo request to; but in order to do so correctly, I would need an accurate recording of how many undo stops are being emitted by each of the monaco editors as their models change. For even more context, see here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with IModelContentChangedEvent and model.onDidChangeContent, then trace how alternativeVersionId relates to the undo-stop decisions described in the issue. Done means the content-change event reliably indicates when a new undo-stack element is created, supporting the multi-editor undo integration described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100