问题
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:
- Step 1.
- Step 2.
- CKEDITOR.instances.editor.fire( 'lockSnapshot' )
- Step 3.
- 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