admin管理员组文章数量:1325137
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 badges1 Answer
Reset to default 8To 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 :).
版权声明:本文标题:javascript - CKEDITOR 4 How to make snapshot before using custom command to use CTRL+Z to undo - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742172524a2426978.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论