X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fundo%2Fplugin.js;h=337c427cd3ad92190756aabb3b86109b65cb4224;hb=refs%2Ftags%2Fv3.6.2;hp=95bd04a1ddb14f859bff18e52f81667c32f6575c;hpb=48b1db88210b4160dce439c6e3e32e14af8c106b;p=ckeditor.git diff --git a/_source/plugins/undo/plugin.js b/_source/plugins/undo/plugin.js index 95bd04a..337c427 100644 --- a/_source/plugins/undo/plugin.js +++ b/_source/plugins/undo/plugin.js @@ -64,9 +64,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.on( 'afterCommandExec', recordCommand ); // Save snapshots before doing custom changes. - editor.on( 'saveSnapshot', function() + editor.on( 'saveSnapshot', function( evt ) { - undoManager.save(); + undoManager.save( evt.data && evt.data.contentOnly ); }); // Registering keydown on every document recreation.(#3844) @@ -90,7 +90,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Make the undo manager available only in wysiwyg mode. editor.on( 'mode', function() { - undoManager.enabled = editor.mode == 'wysiwyg'; + undoManager.enabled = editor.readOnly ? false : editor.mode == 'wysiwyg'; undoManager.onChange(); }); @@ -116,24 +116,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }; /** - * Update the undo stacks with any subsequent DOM changes after this call. + * Amend the top of undo stack (last undo image) with the current DOM changes. * @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.fire( 'saveSnapshot' ); * editor.document.body.append(...); + * // Make new changes following the last undo snapshot part of it. + * editor.fire( 'updateSnapshot' ); * ... * } */ editor.on( 'updateSnapshot', function() { - if ( undoManager.currentImage && new Image( editor ).equals( undoManager.currentImage ) ) - setTimeout( function() { undoManager.update(); }, 0 ); + if ( undoManager.currentImage ) + undoManager.update(); }); } }); @@ -148,6 +146,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var Image = CKEDITOR.plugins.undo.Image = function( editor ) { this.editor = editor; + + editor.fire( 'beforeUndoImage' ); + var contents = editor.getSnapshot(), selection = contents && editor.getSelection(); @@ -156,6 +157,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.contents = contents; this.bookmarks = selection && selection.createBookmarks2( true ); + + editor.fire( 'afterUndoImage' ); }; // Attributes that browser may changing them when setting via innerHTML. @@ -540,6 +543,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license /** * The number of undo steps to be saved. The higher this setting value the more * memory is used for it. + * @name CKEDITOR.config.undoStackSize * @type Number * @default 20 * @example @@ -552,3 +556,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * @name CKEDITOR.editor#saveSnapshot * @event */ + +/** + * Fired before an undo image is to be taken. An undo image represents the + * editor state at some point. It's saved into an undo store, so the editor is + * able to recover the editor state on undo and redo operations. + * @name CKEDITOR.editor#beforeUndoImage + * @since 3.5.3 + * @see CKEDITOR.editor#afterUndoImage + * @event + */ + +/** + * Fired after an undo image is taken. An undo image represents the + * editor state at some point. It's saved into an undo store, so the editor is + * able to recover the editor state on undo and redo operations. + * @name CKEDITOR.editor#afterUndoImage + * @since 3.5.3 + * @see CKEDITOR.editor#beforeUndoImage + * @event + */