我想在ACE editor中重置撤消堆栈。行为应该是:
我想这与ACE的UndoManager
有关,但我不知道如何在以下示例中使用它。
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>
&#13;
我已查看editor
和editor.session
原型以找到一些辅助函数,但没有成功。
答案 0 :(得分:19)
是的,UndoManager
是维护所有历史记录的类。
解决方案是使用空白/新创建的类初始化会话。
查看代码段。
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);
&#13;
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
font-size: 25px;
}
&#13;
<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>
&#13;
答案 1 :(得分:5)
使用editor.session.setValue()
或致电editor.session.getUndoManager().reset();
,请参阅https://github.com/ajaxorg/ace/blob/v1.1.9/lib/ace/edit_session.js#L279