Fixed user suggestions inside Redactor
authorAlexander Ebert <ebert@woltlab.com>
Tue, 6 Jun 2017 11:49:26 +0000 (13:49 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 6 Jun 2017 11:49:26 +0000 (13:49 +0200)
wcfsetup/install/files/js/WCF.Message.js

index fd0cf760958f45b03e6848e630b8eb288e229d87..000745b9bb1d57a4241a0f2d8bc5d4a0eb14c182 100644 (file)
@@ -3648,6 +3648,13 @@ WCF.Message.UserMention = Class.extend({
                        $startOffset = $startContainer.textContent.length - 1;
                }
                
+               // check if `$startContainer` is an element, as it causes `$startOffset` to be
+               // relative to the child nodes instead of the actual text length
+               if ($startContainer.nodeType === Node.ELEMENT_NODE && $startOffset > 0) {
+                       $startContainer = $startContainer.childNodes[$startOffset - 1];
+                       $startOffset = $startContainer.textContent.length;
+               }
+               
                $startOffset -= (this._mentionStart.length + 1);
                
                // navigating with the keyboard before hitting enter will cause the text node to be split