From 4cfde35256cecab12d317e0d829769143f4df2d0 Mon Sep 17 00:00:00 2001
From: Girish S <girish.sonawane@gmail.com>
Date: Mon, 26 Oct 2015 12:25:14 +0530
Subject: append * to search query if not present and highlight partial matches

---
 web/react/utils/text_formatting.jsx | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

(limited to 'web/react/utils/text_formatting.jsx')

diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx
index 5c2e68f1e..75f6cb714 100644
--- a/web/react/utils/text_formatting.jsx
+++ b/web/react/utils/text_formatting.jsx
@@ -243,10 +243,11 @@ function autolinkHashtags(text, tokens) {
 
 function highlightSearchTerm(text, tokens, searchTerm) {
     let output = text;
+    searchTerm = searchTerm.replace(/\*$/, '');
 
     var newTokens = new Map();
     for (const [alias, token] of tokens) {
-        if (token.originalText === searchTerm) {
+        if (token.originalText.indexOf(searchTerm) > -1) {
             const index = tokens.size + newTokens.size;
             const newAlias = `MM_SEARCHTERM${index}`;
 
@@ -276,7 +277,7 @@ function highlightSearchTerm(text, tokens, searchTerm) {
         return prefix + alias;
     }
 
-    return output.replace(new RegExp(`(^|\\W)(${searchTerm})\\b`, 'gi'), replaceSearchTermWithToken);
+   return output.replace(new RegExp(`()(${searchTerm})`, 'gi'), replaceSearchTermWithToken);
 }
 
 function replaceTokens(text, tokens) {
-- 
cgit v1.2.3-1-g7c22

