diff --git a/Changelog.md b/Changelog.md index 8afc63935..e9111f660 100644 --- a/Changelog.md +++ b/Changelog.md @@ -31,6 +31,7 @@ * Restore comment textarea content after revealing more comments [#4514](https://github.com/diaspora/diaspora/issues/4514) * OpenGraph: don't make description into links [#4492](https://github.com/diaspora/diaspora/issues/4492) * Don't cut off long tags in stream posts [#4864](https://github.com/diaspora/diaspora/issues/4864) +* Do not replace earlier appearances of the name while mentioning somebody [#4868](https://github.com/diaspora/diaspora/issues/4868) ## Features * You can report a single post by clicking the correct icon in the controler section [#4517](https://github.com/diaspora/diaspora/pull/4517) diff --git a/lib/assets/javascripts/jquery.mentionsInput.js b/lib/assets/javascripts/jquery.mentionsInput.js index 6fcfa40be..17dca0f81 100644 --- a/lib/assets/javascripts/jquery.mentionsInput.js +++ b/lib/assets/javascripts/jquery.mentionsInput.js @@ -6,6 +6,11 @@ * Using underscore.js * * License: MIT License - http://www.opensource.org/licenses/mit-license.php + * + * Modifcations for Diaspora: + * + * Prevent replacing the wrong text by marking the replacement position with a special character + * Don't add a space after inserting a mention */ (function ($, _, undefined) { @@ -69,6 +74,7 @@ var autocompleteItemCollection = {}; var inputBuffer = []; var currentDataQuery = ''; + var mentionChar = "\u200B"; // zero width space settings = $.extend(true, {}, defaultSettings, settings ); @@ -114,13 +120,13 @@ _.each(mentionsCollection, function (mention) { var textSyntax = settings.templates.mentionItemSyntax(mention); - syntaxMessage = syntaxMessage.replace(mention.value, textSyntax); + syntaxMessage = syntaxMessage.replace(mentionChar + mention.value, textSyntax); }); var mentionText = utils.htmlEncode(syntaxMessage); _.each(mentionsCollection, function (mention) { - var formattedMention = _.extend({}, mention, {value: utils.htmlEncode(mention.value)}); + var formattedMention = _.extend({}, mention, {value: mentionChar + utils.htmlEncode(mention.value)}); var textSyntax = settings.templates.mentionItemSyntax(formattedMention); var textHighlight = settings.templates.mentionItemHighlight(formattedMention); @@ -170,7 +176,7 @@ hideAutoComplete(); // Mentions & syntax message - var updatedMessageText = start + mention.value + end; + var updatedMessageText = start + mentionChar + mention.value + end; elmInputBox.val(updatedMessageText); updateValues();