I want to reset the undo stack in an ACE editor. The behavior should be:
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.
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);
editor.getSession().setUndoManager(new ace.UndoManager())
}, 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>
use editor.session.setValue()
or call editor.session.getUndoManager().reset();
see https://github.com/ajaxorg/ace/blob/v1.1.9/lib/ace/edit_session.js#L279
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With