[BUGFIX] htmlArea RTE: Cursor jumps to first letter with Chrome 22
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 4 Oct 2012 17:42:00 +0000 (13:42 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Tue, 9 Oct 2012 13:59:07 +0000 (15:59 +0200)
Selection gets broken when bookmarks are inserted by undo/redo
mechanism in Google Chrome 22.

Change-Id: Ic5ba765925611c7b83a67786f64a292908ea5076
Resolves: #41411
Releases: 4.5, 4.6, 4.7, 6.0
Reviewed-on: http://review.typo3.org/15335
Reviewed-by: Stanislas Rolland
Tested-by: Stanislas Rolland
typo3/sysext/rtehtmlarea/htmlarea/plugins/UndoRedo/undo-redo.js

index e7407bb..d9ac9b4 100644 (file)
@@ -171,7 +171,8 @@ HTMLArea.UndoRedo = HTMLArea.Plugin.extend({
                        if ((!Ext.isIE && !(Ext.isOpera && navigator.userAgent.toLowerCase().indexOf('presto/2.1') != -1)) || (Ext.isIE && selection.type.toLowerCase() != 'control')) {
                                        // Catch error in FF when the selection contains no usable range
                                try {
-                                       bookmark = this.editor.getBookmark(this.editor._createRange(selection));
+                                       var range = this.editor._createRange(selection);
+                                       bookmark = this.editor.getBookmark(range);
                                } catch (e) {
                                        bookmark = null;
                                }
@@ -179,9 +180,13 @@ HTMLArea.UndoRedo = HTMLArea.Plugin.extend({
                                // Get the bookmarked html text and remove the bookmark
                        if (bookmark) {
                                bookmarkedText = this.editor.getInnerHTML();
+                                       // Working aroung buggy Google Chrome 22 (selection broken by inserted bookmark node)
+                               if (Ext.isChrome) {
+                                       this.editor.setHTML(bookmarkedText);
+                               }
                                var range = this.editor.moveToBookmark(bookmark);
                                        // Restore Firefox selection
-                               if (Ext.isGecko) {
+                               if (Ext.isGecko || Ext.isChrome) {
                                        this.editor.emptySelection(selection);
                                        this.editor.addRangeToSelection(selection, range);
                                }