From 6b22a8e81660881baa2ecb7d4cdd7b5abb2ff0b0 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 22 Jun 2016 18:32:59 -0400 Subject: PLT-3211 Fixed search highlighting for hashtags starting with "#in", "#from", or "#channel" (#3400) * Fixed clicking hashtags/@mentions adding a # to the url * Updated punctuation trimming regex for searching to better match the server * Fixed search term splitting to not break up hashtags starting with a search flag (in, from, etc) --- webapp/utils/text_formatting.jsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'webapp') diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx index dbf18d722..7f4328dc9 100644 --- a/webapp/utils/text_formatting.jsx +++ b/webapp/utils/text_formatting.jsx @@ -298,8 +298,8 @@ function autolinkHashtags(text, tokens) { return output.replace(/(^|\W)(#[a-zA-ZäöüÄÖÜß][a-zA-Z0-9äöüÄÖÜß.\-_]*)\b/g, replaceHashtagWithToken); } -const puncStart = /^[.,()&$!\[\]{}':;\\]+/; -const puncEnd = /[.,()&$#!\[\]{}':;\\]+$/; +const puncStart = /^[^a-zA-Z0-9#]+/; +const puncEnd = /[^a-zA-Z0-9]+$/; function parseSearchTerms(searchTerm) { let terms = []; @@ -334,7 +334,7 @@ function parseSearchTerms(searchTerm) { } // capture any plain text up until the next quote or search flag - captured = (/^.+?(?=\bin|\bfrom|\bchannel|"|$)/).exec(termString); + captured = (/^.+?(?=\bin:|\bfrom:|\bchannel:|"|$)/).exec(termString); if (captured) { termString = termString.substring(captured[0].length); @@ -446,8 +446,12 @@ export function handleClick(e) { const linkAttribute = e.target.getAttributeNode('data-link'); if (mentionAttribute) { + e.preventDefault(); + Utils.searchForTerm(mentionAttribute.value); } else if (hashtagAttribute) { + e.preventDefault(); + Utils.searchForTerm(hashtagAttribute.value); } else if (linkAttribute) { const MIDDLE_MOUSE_BUTTON = 1; @@ -465,4 +469,4 @@ function insertLongLinkWbr(test) { return test.replace(/\//g, (match, position, string) => { return match + ((/a[^>]*>[^<]*$/).test(string.substr(0, position)) ? '' : ''); }); -} \ No newline at end of file +} -- cgit v1.2.3-1-g7c22