Fixed issues with split nodes
authorAlexander Ebert <ebert@woltlab.com>
Tue, 24 Feb 2015 16:52:58 +0000 (17:52 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 24 Feb 2015 16:53:08 +0000 (17:53 +0100)
wcfsetup/install/files/js/WCF.Message.js

index bbfb755a8f227ffaf3f838ec720f52afe93815ff..e05a1c325d63a64ad57ccc2c920c5be8e6227042 100644 (file)
@@ -3598,8 +3598,17 @@ WCF.Message.UserMention = Class.extend({
                // allow redactor to undo this
                this._redactor.buffer.set();
                
+               var $startContainer = $orgRange.startContainer;
+               var $startOffset = $orgRange.startOffset - (this._mentionStart.length + 1);
+               
+               // navigating with the keyboard before hitting enter will cause the text node to be split
+               if ($startOffset < 0) {
+                       $startContainer = $startContainer.previousSibling;
+                       $startOffset = $startContainer.length - (this._mentionStart.length + 1) - ($orgRange.startOffset - 1);
+               }
+               
                var $newRange = document.createRange();
-               $newRange.setStart($orgRange.startContainer, $orgRange.startOffset - (this._mentionStart.length + 1));
+               $newRange.setStart($startContainer, $startOffset);
                $newRange.setEnd($orgRange.startContainer, $orgRange.startOffset);
                
                this._redactor.wutil.replaceRangesWith($newRange);