我们遇到了同样的问题,但解决方案有点老套。在 tinymce 核心中有一个 JavaScript 类,我们需要覆盖:tinymce.UndoManager
.
我们使用一个附加到编辑器对象的变量来决定是否应该创建撤消步骤tinymce.activeEditor.disable_undo_creation
:这是覆盖类的代码部分:
add : function(level) {
if (tinymce.activeEditor.disable_undo_creation) return;
var i, settings = editor.settings, lastLevel;
level = level || {};
level.content = getContent();
// Add undo level if needed
lastLevel = data[index];
if (lastLevel && lastLevel.content == level.content)
return null;
// Time to compress
if (settings.custom_undo_redo_levels) {
if (data.length > settings.custom_undo_redo_levels) {
for (i = 0; i < data.length - 1; i++)
data[i] = data[i + 1];
data.length--;
index = data.length;
}
}
// Get a non intrusive normalized bookmark
level.bookmark = editor.selection.getBookmark(2, true);
// Crop array if needed
if (index < data.length - 1)
data.length = index + 1;
data.push(level);
index = data.length - 1;
self.onAdd.dispatch(self, level);
editor.isNotDirty = 0;
return level;
},
当编辑器无法创建撤消步骤时,重做/撤消将不再起作用。