最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CKEDITOR 4 How to make snapshot before using custom command to use CTRL+Z to undo - Stack Overflow

programmeradmin3浏览0评论

Problem is following:

We have custom block element, such as quote.

We want to have a possibility to "CTRL+Z" (Undo) its creation.

How to make snapshot of current state of ckeditor before inserting its html, so CTRL+Z after that would be usable?

Problem is following:

We have custom block element, such as quote.

We want to have a possibility to "CTRL+Z" (Undo) its creation.

How to make snapshot of current state of ckeditor before inserting its html, so CTRL+Z after that would be usable?

Share Improve this question asked Nov 9, 2013 at 16:42 WaterlinkWaterlink 2,3691 gold badge18 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

To save a snapshot just fire saveSnapshot event on editor instance. You have to do this before and after performing an action which should be recorded as a separate snapshot. For example:

editor.fire( 'saveSnapshot' );
editor.insertHtml( '...' );
editor.fire( 'saveSnapshot' );

Also, if your functionality is a single mand, remember that editor records snapshots whenever you execute it. So this wouldn't make sense:

editor.fire( 'saveSnapshot' );
editor.execCommand( 'myCmd' );
editor.fire( 'saveSnapshot' );

Update: If you want to merge some operations which could make their own snapshots (like executed mand) then you can lock snapshot before performing them and unlock after.

editor.fire( 'lockSnapshot' );
editor.execCommand( 'myCmd1' );
editor.execCommand( 'myCmd2' );
editor.fire( 'unlockSnapshot' );

While snapshot is locked new snapshots won't be recorder. If snapshot stack was up to date in the moment of locking the snapshot, then unlockSnapshot will update the last snapshot. But if it wasn't then all those changes will not be recorded until next saveSnapshot is fired.

This is a bit tricky and requires some practice and testing to start using this mechanism properly :).

发布评论

评论列表(0)

  1. 暂无评论