JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _source / plugins / undo / plugin.js
index 337c427..f4ad1a3 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -260,7 +260,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        if ( startedTyping || modifierSnapshot )\r
                        {\r
-                               var beforeTypeImage = new Image( this.editor );\r
+                               var beforeTypeImage = new Image( this.editor ),\r
+                                       beforeTypeCount = this.snapshots.length;\r
 \r
                                // Use setTimeout, so we give the necessary time to the\r
                                // browser to insert the character into the DOM.\r
@@ -272,7 +273,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                if ( CKEDITOR.env.ie )\r
                                                        currentSnapshot = currentSnapshot.replace( /\s+data-cke-expando=".*?"/g, '' );\r
 \r
-                                               if ( beforeTypeImage.contents != currentSnapshot )\r
+                                               // If changes have taken place, while not been captured yet (#8459),\r
+                                               // compensate the snapshot.\r
+                                               if ( beforeTypeImage.contents != currentSnapshot &&\r
+                                                        beforeTypeCount == this.snapshots.length )\r
                                                {\r
                                                        // It's safe to now indicate typing state.\r
                                                        this.typing = true;\r
@@ -410,10 +414,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                restoreImage : function( image )\r
                {\r
+                       // Bring editor focused to restore selection.\r
+                       var editor = this.editor,\r
+                               sel;\r
+\r
+                       if ( image.bookmarks )\r
+                       {\r
+                               editor.focus();\r
+                               // Retrieve the selection beforehand. (#8324)\r
+                               sel = editor.getSelection();\r
+                       }\r
+\r
                        this.editor.loadSnapshot( image.contents );\r
 \r
                        if ( image.bookmarks )\r
-                               this.editor.getSelection().selectBookmarks( image.bookmarks );\r
+                               sel.selectBookmarks( image.bookmarks );\r
                        else if ( CKEDITOR.env.ie )\r
                        {\r
                                // IE BUG: If I don't set the selection to *somewhere* after setting\r