X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fundo%2Fplugin.js;h=fde581f07014eb0e599f49a164c0a4d6e0722a5c;hp=e843d2360710aa1d7ac759e3bed73af0fed8b0d7;hb=8665a7c6c60586526e32e8941fe2896739b6ebfb;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1 diff --git a/_source/plugins/undo/plugin.js b/_source/plugins/undo/plugin.js index e843d23..fde581f 100644 --- a/_source/plugins/undo/plugin.js +++ b/_source/plugins/undo/plugin.js @@ -114,13 +114,41 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Create the first image. editor.fire( 'saveSnapshot' ); }; + + /** + * Update the undo stacks with any subsequent DOM changes after this call. + * @name CKEDITOR.editor#updateUndo + * @example + * function() + * { + * editor.fire( 'updateSnapshot' ); + * ... + * // Ask to include subsequent (in this call stack) DOM changes to be + * // considered as part of the first snapshot. + * editor.fire( 'updateSnapshot' ); + * editor.document.body.append(...); + * ... + * } + */ + editor.on( 'updateSnapshot', function() + { + if ( undoManager.currentImage && new Image( editor ).equals( undoManager.currentImage ) ) + setTimeout( function () { undoManager.update(); }, 0 ); + }); } }); - // Gets a snapshot image which represent the current document status. - function Image( editor ) + CKEDITOR.plugins.undo = {}; + + /** + * Undo snapshot which represents the current document status. + * @name CKEDITOR.plugins.undo.Image + * @param editor The editor instance on which the image is created. + */ + var Image = CKEDITOR.plugins.undo.Image = function( editor ) { - var contents = editor.getSnapshot(), + this.editor = editor; + var contents = editor.getSnapshot(), selection = contents && editor.getSelection(); // In IE, we need to remove the expando attributes. @@ -128,7 +156,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.contents = contents; this.bookmarks = selection && selection.createBookmarks2( true ); - } + }; // Attributes that browser may changing them when setting via innerHTML. var protectedAttrs = /\b(?:href|src|name)="[^"]*?"/gi; @@ -137,6 +165,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { equals : function( otherImage, contentOnly ) { + var thisContents = this.contents, otherContents = otherImage.contents; @@ -397,8 +426,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Update current image with the actual editor // content, since actualy content may differ from // the original snapshot due to dom change. (#4622) - this.snapshots.splice( this.index, 1, ( this.currentImage = new Image( this.editor ) ) ); - + this.update(); this.fireChange(); }, @@ -497,6 +525,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } return false; + }, + + /** + * Update the last snapshot of the undo stack with the current editor content. + */ + update : function() + { + this.snapshots.splice( this.index, 1, ( this.currentImage = new Image( this.editor ) ) ); } }; })();