From 824917b029826384129e504e83739fcc55541b4f Mon Sep 17 00:00:00 2001
From: nickago <ngonella@calpoly.edu>
Date: Thu, 13 Aug 2015 15:52:52 -0700
Subject: Added wildcard highlighting and removed redundant whitespace parsing

---
 web/react/utils/utils.jsx | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

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

diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index f0cf17446..66740d380 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -457,9 +457,21 @@ module.exports.textToJsx = function(text, options) {
             var mentionRegex = /^(?:@)([a-z0-9_]+)$/gi; // looks loop invariant but a weird JS bug needs it to be redefined here
             var explicitMention = mentionRegex.exec(trimWord);
 
-            if ((trimWord.toLowerCase().indexOf(searchTerm) > -1 || word.toLowerCase().indexOf(searchTerm) > -1) && searchTerm != '') {
-
-                highlightSearchClass = ' search-highlight';
+            if (searchTerm !== '') {
+                let searchWords = searchTerm.split(' ');
+                for (let idx in searchWords) {
+                    let searchWord = searchWords[idx];
+                    if (searchWord === word.toLowerCase() || searchWord === trimWord.toLowerCase()) {
+                        highlightSearchClass = ' search-highlight';
+                        break;
+                    } else if (searchWord.charAt(searchWord.length - 1) === '*') {
+                        let searchWordPrefix = searchWord.slice(0,-1);
+                        if (trimWord.toLowerCase().indexOf(searchWordPrefix) > -1 || word.toLowerCase().indexOf(searchWordPrefix) > -1) {
+                            highlightSearchClass = ' search-highlight';
+                            break;
+                        }
+                    }
+                }
             }
 
             if (explicitMention &&
-- 
cgit v1.2.3-1-g7c22

