// Create the first image.\r
editor.fire( 'saveSnapshot' );\r
};\r
+\r
+ /**\r
+ * Update the undo stacks with any subsequent DOM changes after this call.\r
+ * @name CKEDITOR.editor#updateUndo\r
+ * @example\r
+ * function()\r
+ * {\r
+ * editor.fire( 'updateSnapshot' );\r
+ * ...\r
+ * // Ask to include subsequent (in this call stack) DOM changes to be\r
+ * // considered as part of the first snapshot.\r
+ * editor.fire( 'updateSnapshot' );\r
+ * editor.document.body.append(...);\r
+ * ...\r
+ * }\r
+ */\r
+ editor.on( 'updateSnapshot', function()\r
+ {\r
+ if ( undoManager.currentImage && new Image( editor ).equals( undoManager.currentImage ) )\r
+ setTimeout( function () { undoManager.update(); }, 0 );\r
+ });\r
}\r
});\r
\r
- // Gets a snapshot image which represent the current document status.\r
- function Image( editor )\r
+ CKEDITOR.plugins.undo = {};\r
+\r
+ /**\r
+ * Undo snapshot which represents the current document status.\r
+ * @name CKEDITOR.plugins.undo.Image\r
+ * @param editor The editor instance on which the image is created.\r
+ */\r
+ var Image = CKEDITOR.plugins.undo.Image = function( editor )\r
{\r
- var contents = editor.getSnapshot(),\r
+ this.editor = editor;\r
+ var contents = editor.getSnapshot(),\r
selection = contents && editor.getSelection();\r
\r
// In IE, we need to remove the expando attributes.\r
\r
this.contents = contents;\r
this.bookmarks = selection && selection.createBookmarks2( true );\r
- }\r
+ };\r
\r
// Attributes that browser may changing them when setting via innerHTML.\r
var protectedAttrs = /\b(?:href|src|name)="[^"]*?"/gi;\r
{\r
equals : function( otherImage, contentOnly )\r
{\r
+\r
var thisContents = this.contents,\r
otherContents = otherImage.contents;\r
\r
// Update current image with the actual editor\r
// content, since actualy content may differ from\r
// the original snapshot due to dom change. (#4622)\r
- this.snapshots.splice( this.index, 1, ( this.currentImage = new Image( this.editor ) ) );\r
-\r
+ this.update();\r
this.fireChange();\r
},\r
\r
}\r
\r
return false;\r
+ },\r
+\r
+ /**\r
+ * Update the last snapshot of the undo stack with the current editor content.\r
+ */\r
+ update : function()\r
+ {\r
+ this.snapshots.splice( this.index, 1, ( this.currentImage = new Image( this.editor ) ) );\r
}\r
};\r
})();\r