X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fundo%2Fplugin.js;h=f4ad1a3c6b0f16141f7b8457e0a55aff9107ba7c;hb=2f22c0c38f17e75be5541089076885442aaa2377;hp=8801be239999947890ac2b212257d993503bb64f;hpb=9afde8772159bd3436f1f5b7862960307710ae5a;p=ckeditor.git diff --git a/_source/plugins/undo/plugin.js b/_source/plugins/undo/plugin.js index 8801be2..f4ad1a3 100644 --- a/_source/plugins/undo/plugin.js +++ b/_source/plugins/undo/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -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. @@ -257,7 +260,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( startedTyping || modifierSnapshot ) { - var beforeTypeImage = new Image( this.editor ); + var beforeTypeImage = new Image( this.editor ), + beforeTypeCount = this.snapshots.length; // Use setTimeout, so we give the necessary time to the // browser to insert the character into the DOM. @@ -269,7 +273,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( CKEDITOR.env.ie ) currentSnapshot = currentSnapshot.replace( /\s+data-cke-expando=".*?"/g, '' ); - if ( beforeTypeImage.contents != currentSnapshot ) + // If changes have taken place, while not been captured yet (#8459), + // compensate the snapshot. + if ( beforeTypeImage.contents != currentSnapshot && + beforeTypeCount == this.snapshots.length ) { // It's safe to now indicate typing state. this.typing = true; @@ -407,10 +414,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license restoreImage : function( image ) { + // Bring editor focused to restore selection. + var editor = this.editor, + sel; + + if ( image.bookmarks ) + { + editor.focus(); + // Retrieve the selection beforehand. (#8324) + sel = editor.getSelection(); + } + this.editor.loadSnapshot( image.contents ); if ( image.bookmarks ) - this.editor.getSelection().selectBookmarks( image.bookmarks ); + sel.selectBookmarks( image.bookmarks ); else if ( CKEDITOR.env.ie ) { // IE BUG: If I don't set the selection to *somewhere* after setting @@ -540,6 +558,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 +571,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 + */