-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
As it is, undo / redo is completely unusable when applying decorations.
Here is an old issue that essentially requested the same thing from a couple of years ago, but was marked as something the team did not plan to address.
The decorations have evolved quite a bit over the past couple years and this would be a worthwhile addition for anyone using decorations.
Also, the Undo / Redo functionality as it is does not have many helpful API's available. We cannot look at the undo/redo stack at all (unless I'm missing something?), so any custom undo/redo functionality is impossible without completely overriding the action, which is what I currently plan to do for my use case.
Monaco Editor Playground Code
var jsCode = [
'"use strict";',
'function Person(age) {',
' if (age) {',
' this.age = age;',
' }',
'}',
'Person.prototype.getAge = function () {',
' return this.age;',
'};'
].join('\n');
var editor = monaco.editor.create(document.getElementById('container'), {
value: jsCode,
language: 'javascript'
});
var decorations = editor.deltaDecorations(
[],
[
{
range: new monaco.Range(3, 1, 5, 1),
options: {
isWholeLine: true,
linesDecorationsClassName: 'myLineDecoration'
}
},
{
range: new monaco.Range(7, 1, 7, 24),
options: { inlineClassName: 'myInlineDecoration' }
}
]
);
setTimeout(() => {
editor.getModel().deltaDecorations(
[],
[{
range: new monaco.Range(7, 27, 7, 35),
options: {inlineClassName: 'myInlineDecoration'}
}]
)
}, 5000)
Reproduction Steps
- The code is set up to do a deltaDecoration call on the word "function" after a 5 second timeout
- Type anything in the middle of the word "function"
- Let the decoration apply
- Undo
Actual (Problematic) Behavior
Your text edit will be undone, and the decoration will be applied only to the text before you started typing
After applying decoration:

After undoing:

Expected Behavior
Undo should revert the deltaDecoration call, the text should remain as "fun123456ction", and should have no decoration
Additional Context
No response