[英]Reset the undo stack in ACE editor
I want to reset the undo stack in an ACE editor . 我想在ACE编辑器中重置撤消堆栈。 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. 我想这与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>
I have looked into editor
and editor.session
prototypes to find some helper function, but without success. 我已经查看了
editor
和editor.session
原型来找到一些辅助函数,但没有成功。
Yes, UndoManager
is the class which maintains all the history. 是的,
UndoManager
是维护所有历史记录的类。 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();
使用
editor.session.setValue()
或调用editor.session.getUndoManager().reset();
see https://github.com/ajaxorg/ace/blob/v1.1.9/lib/ace/edit_session.js#L279 请参阅https://github.com/ajaxorg/ace/blob/v1.1.9/lib/ace/edit_session.js#L279
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.