From 727a863fd8fdd42cd73df6a1ac9ef4c5cdbaae4f Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 13 Apr 2014 12:01:39 +0200 Subject: [PATCH] Fix issues with mentions (in Firefox) --- wcfsetup/install/files/js/WCF.Message.js | 35 ++++++++++++------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 82c3539db2..8015ebe36b 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -3300,8 +3300,18 @@ WCF.Message.UserMention = Class.extend({ _setUsername: function(username) { var $range = this._ckEditor.getSelection().getRanges()[0]; - // remove the beginning of the username + // remove the beginning of the username and the '@' $range.setStart($range.startContainer, $range.startOffset - (this._mentionStart.length + 1)); + + // if an existing mention is edited, remove the link around it + var $removedLink = false; + var $commonAncestor = $range.getCommonAncestor(); + if ($commonAncestor.getText() == '@' + this._mentionStart) { + if ($commonAncestor.getParent() && $commonAncestor.getParent().getName() == 'a') { + $commonAncestor.replace($commonAncestor.getParent()); + $range.setStart($commonAncestor); + } + } $range.deleteContents(); // insert username @@ -3312,23 +3322,12 @@ WCF.Message.UserMention = Class.extend({ else if (username.indexOf(' ') !== -1) { username = "'" + username + "'"; } - this._ckEditor.insertText('@' + username); - - // add whitespace after username - var $element = CKEDITOR.dom.element.createFromHtml(' '); - this._ckEditor.insertElement($element); - $(this._ckEditor.document.$).find('span.wcfUserMentionTemporary').replaceWith(function() { - return $(this).html(); - }); - - // make sure that the range in Firefox is that same as in the - // other browsers - if ($.browser.mozilla) { - $range.selectNodeContents(new CKEDITOR.dom.text($range.endContainer.$.nextSibling)); - $range.setStart($range.startContainer, 1); - $range.select(); - } - + var $usernameNode = new CKEDITOR.dom.text('@' + username); + $range.insertNode($usernameNode); + $range.selectNodeContents($usernameNode); + $range.collapse(false); + $range.select(); + this._hideList(); }, -- 2.20.1