简体   繁体   English

在ACE编辑器中重置撤消堆栈

[英]Reset the undo stack in ACE editor

I want to reset the undo stack in an ACE editor . 我想在ACE编辑器中重置撤消堆栈。 The behavior should be: 行为应该是:

  1. I do some changes in editor. 我在编辑器中做了一些更改。
  2. Call some magic function to reset the undo stack 调用一些魔术函数来重置撤消堆栈
  3. 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. 我想这与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. 我已经查看了editoreditor.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM