From 16df77807e4acf500ec1d7263528c60ac36ec6f8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 24 Feb 2015 17:52:58 +0100 Subject: [PATCH] Fixed issues with split nodes --- wcfsetup/install/files/js/WCF.Message.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index bbfb755a8f..e05a1c325d 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -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); -- 2.20.1