How to discard only the last element of CKEditor undo stack?

荒凉一梦 提交于 2019-12-11 02:05:03

问题


Is there a way to remove only the last snapshot in the CKEditor undo stack or can i replace it with another.Should i implement it on my own?

Example:

Step 1

Step 2 --should be removed and replaced with step 3 (On given situation)

Step 3 -- should become step 2

This feature should be available only if special event occurs.


回答1:


If your undo snapshots are a result of user actions, following this way:

  1. Step 1.
  2. Step 2.
  3. CKEDITOR.instances.editor.fire( 'lockSnapshot' )
  4. Step 3.
  5. CKEDITOR.instances.editor.fire( 'unlockSnapshot' )

Of course, you have to detect what's going on and fire the right event at the right time.

If changes to the content are done from code, editor#updateSnapshot event would even be better:

function() {
    editor.fire( 'saveSnapshot' );
    editor.document.body.append(...);
    // Makes new changes following the last undo snapshot a part of it.
    editor.fire( 'updateSnapshot' );
    ..
}


来源:https://stackoverflow.com/questions/29407895/how-to-discard-only-the-last-element-of-ckeditor-undo-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!