summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorGirish S <girish.sonawane@gmail.com>2015-10-26 12:25:14 +0530
committerGirish S <girish.sonawane@gmail.com>2015-10-26 12:25:14 +0530
commit4cfde35256cecab12d317e0d829769143f4df2d0 (patch)
treea80b99e8cbe4bb1fd10b5c3164f8365e592d326f /web
parentae2898107d275176126ab07ca1886fd7fd7ddad4 (diff)
downloadchat-4cfde35256cecab12d317e0d829769143f4df2d0.tar.gz
chat-4cfde35256cecab12d317e0d829769143f4df2d0.tar.bz2
chat-4cfde35256cecab12d317e0d829769143f4df2d0.zip
append * to search query if not present and highlight partial matches
Diffstat (limited to 'web')
-rw-r--r--web/react/components/search_bar.jsx4
-rw-r--r--web/react/utils/text_formatting.jsx5
2 files changed, 7 insertions, 2 deletions
diff --git a/web/react/components/search_bar.jsx b/web/react/components/search_bar.jsx
index e1d36ad7d..fae26f803 100644
--- a/web/react/components/search_bar.jsx
+++ b/web/react/components/search_bar.jsx
@@ -105,6 +105,10 @@ export default class SearchBar extends React.Component {
performSearch(terms, isMentionSearch) {
if (terms.length) {
this.setState({isSearching: true});
+
+ if(terms.search(/\*\s*$/) == -1) // append * if not present
+ terms = terms + "*";
+
client.search(
terms,
(data) => {
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) {