I want to reset the undo stack in an ACE editor. The behavior should be:
- I do some changes in editor.
- Call some magic function to reset the undo stack
- When trying to undo, this will not be possible because the undo stack was reset.
I guess it has to do with the UndoManager
from ACE, but I have no idea how can I use it in the following example.
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/markdown");
setTimeout(function() {
editor.setValue("And now how can I reset the\nundo stack,so pressing\nCTRL+Z (or Command + Z) will *NOT*\ngo back to previous value?", -1);
}, 3000);
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
font-size: 25px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.9/ace.js"></script>
<div id="editor">This value will be changed in 3 seconds.</div>
I have looked into editor
and editor.session
prototypes to find some helper function, but without success.
Yes,
UndoManager
is the class which maintains all the history. The solution is to initialize the session with a blank/newly created class.Check out the snippet.