X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fundo%2Fplugin.js;h=b78995ca10d7daf6d6d8fd0532796beef30b4dfd;hb=refs%2Ftags%2Fv3.4.2;hp=e843d2360710aa1d7ac759e3bed73af0fed8b0d7;hpb=c6e377a02b54abc07129d72b632763c727476a15;p=ckeditor.git diff --git a/_source/plugins/undo/plugin.js b/_source/plugins/undo/plugin.js index e843d23..b78995c 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; @@ -310,7 +339,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ this.index = -1; - this.limit = this.editor.config.undoStackSize; + this.limit = this.editor.config.undoStackSize || 20; this.currentImage = null; @@ -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 ) ) ); } }; })(); @@ -509,7 +545,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * @example * config.undoStackSize = 50; */ -CKEDITOR.config.undoStackSize = 20; /** * Fired when the editor is about to save an undo snapshot. This event can be