From ae13de61ccd752815f0cfb15c2ddc850f9fa5d4f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 27 Jan 2014 02:17:12 +0100 Subject: [PATCH] CKEditor: Fix for strange selection bug in Firefox --- wcfsetup/install/files/js/WCF.Message.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 7c5748932d..c698005d1f 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -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); -- 2.20.1