1

In my angular 7 project I'm using monaco editor for the coding. If I do some change in the code and then press ctrl+z then it will undo the code, but when I do some change then I am changing the coding language after that if I press ctrl+z then it will not restore the previous code. So the issue is that after changing the coding language the previous code is not restored by pressing ctrl+z.

Please help me solve the above issue.

1 Answers1

4

Use executeEdits to apply changes while keeping the undo stack:

const myText = 'the replacement text';

// Select all text
const fullRange = editor.getModel().getFullModelRange();

// Apply the text over the range
editor.executeEdits(null, [{
  text: myText,
  range: fullRange
}]);

// Indicates the above edit is a complete undo/redo change.
editor.pushUndoStop();

Editor API: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandalonecodeeditor.html#executeedits

makman99
  • 1,045
  • 14
  • 18