CKEditor: Fix for strange selection bug in Firefox
authorAlexander Ebert <ebert@woltlab.com>
Mon, 27 Jan 2014 01:17:12 +0000 (02:17 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 27 Jan 2014 01:17:12 +0000 (02:17 +0100)
wcfsetup/install/files/js/WCF.Message.js

index 7c5748932d95401a18c644f2f5cd7498cd2a0847..c698005d1f718f1059c62755a832d476d1b50319 100644 (file)
@@ -745,7 +745,17 @@ WCF.Message.QuickReply = Class.extend({
                }
                
                if ($.browser.ckeditor) {
-                       this._messageField.ckeditorGet().insertText(data.returnValues.template);
+                       var $ckEditor = this._messageField.ckeditorGet();
+                       
+                       // work-around for a strange selection bug in Firefox: http://www.woltlab.com/forum/index.php/Thread/220522-Zitat-Fehler/
+                       if ($ckEditor.getSelection().getStartElement() === null) {
+                               // range is broken, set it to end of text: http://stackoverflow.com/a/16308194
+                               var $range = $ckEditor.createRange();
+                               $range.moveToPosition($range.root, CKEDITOR.POSITION_BEFORE_END);
+                               $ckEditor.getSelection().selectRanges([ $range ]);
+                       }
+                       
+                       $ckEditor.insertText(data.returnValues.template);
                }
                else {
                        this._messageField.val(data.returnValues.template);