在单页应用程序中为文本编辑器处理 Ctrl+Z (undo/redo)

Handle Ctrl+Z (undo/redo) for text editor in single page application

我有一个包含文本编辑器(kendo 编辑器)的单页应用程序。文本编辑器中的数据被替换成这样

$("#editor").kendoEditor({
                    resizable: {
                        content: false,
                        toolbar: true
                    }
                });

                var editor = $("#editor").data("kendoEditor");

                var setValue = function () {
                    editor.value($("#value").val());
                };

查看演示 here

问题: 所以我正在更改 A 的记录然后保存它。然后我切换到 B。现在,如果我执行 Ctrl+Z,文本编辑器会显示 A 的记录。我怎样才能防止这种行为。

有没有一种方法可以根据需要删除撤消历史记录,或者可以防止文本编辑器用以前的记录替换文本?

更新:更好的解决方案。

我联系了 Kendo 开发人员,他们提供了一个巧妙的解决方案。

var editor = $("#editor").data("kendoEditor");
editor.undoRedoStack.clear();

Note: this function is not documented in the public api and is may change in newer version. This is working as of version 2016.3.1118

demo

旧解决方案。

我最终销毁了小部件并将其重新绑定到文本区域。

http://dojo.telerik.com/OjIZe

$("#destroy").click(function(){ 
  var copy=$("#editor").clone(); 
  $("#editor").data('kendoEditor').wrapper.find("iframe").remove(); 
  $("#editor").data('kendoEditor').destroy(); 
  $("#test").empty(); 
  $("#test").append(copy); 
  $("#editor").kendoEditor({ resizable:    { 
    content: false, toolbar: true 
  } 
  }); 
});