summaryrefslogtreecommitdiffstats
path: root/webapp/utils
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-08-17 09:35:36 -0700
committerChristopher Speller <crspeller@gmail.com>2017-08-17 09:35:36 -0700
commitfd1301779fecc2910a9fdcf93af52ff33a4349ba (patch)
treeccd8b35d347b77c8c6a99db9422b3dbc0ff3bd2d /webapp/utils
parentd41f1695e99a81808f5dc1fbe7820062947b5291 (diff)
parent0033e3e37b12cb5d951d21492500d66a6abc472b (diff)
downloadchat-fd1301779fecc2910a9fdcf93af52ff33a4349ba.tar.gz
chat-fd1301779fecc2910a9fdcf93af52ff33a4349ba.tar.bz2
chat-fd1301779fecc2910a9fdcf93af52ff33a4349ba.zip
Merge branch 'release-4.1'
Diffstat (limited to 'webapp/utils')
-rw-r--r--webapp/utils/markdown.jsx2
-rw-r--r--webapp/utils/post_utils.jsx9
-rw-r--r--webapp/utils/text_formatting.jsx27
-rw-r--r--webapp/utils/utils.jsx2
4 files changed, 33 insertions, 7 deletions
diff --git a/webapp/utils/markdown.jsx b/webapp/utils/markdown.jsx
index 8733e6200..5918b1581 100644
--- a/webapp/utils/markdown.jsx
+++ b/webapp/utils/markdown.jsx
@@ -175,7 +175,7 @@ class MattermostMarkdownRenderer extends marked.Renderer {
if (this.formattingOptions.searchPatterns) {
for (const pattern of this.formattingOptions.searchPatterns) {
- if (pattern.test(href)) {
+ if (pattern.pattern.test(href)) {
output += ' search-highlight';
break;
}
diff --git a/webapp/utils/post_utils.jsx b/webapp/utils/post_utils.jsx
index 9309e1e49..83fb666af 100644
--- a/webapp/utils/post_utils.jsx
+++ b/webapp/utils/post_utils.jsx
@@ -107,3 +107,12 @@ export function shouldShowDotMenu(post) {
return false;
}
+
+export function containsAtMention(text, key) {
+ if (!text || !key) {
+ return false;
+ }
+
+ // This doesn't work for at mentions containing periods or hyphens
+ return new RegExp(`\\B${key}\\b`, 'i').test(text);
+}
diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx
index 33cc3242c..4602a31b2 100644
--- a/webapp/utils/text_formatting.jsx
+++ b/webapp/utils/text_formatting.jsx
@@ -400,7 +400,10 @@ function convertSearchTermToRegex(term) {
pattern = '\\b()(' + escapeRegex(term) + ')\\b';
}
- return new RegExp(pattern, 'gi');
+ return {
+ pattern: new RegExp(pattern, 'gi'),
+ term
+ };
}
export function highlightSearchTerms(text, tokens, searchPatterns) {
@@ -426,7 +429,21 @@ export function highlightSearchTerms(text, tokens, searchPatterns) {
// highlight existing tokens matching search terms
var newTokens = new Map();
for (const [alias, token] of tokens) {
- if (pattern.test(token.originalText)) {
+ if (pattern.pattern.test(token.originalText)) {
+ // If it's a Hashtag, skip it unless the search term is an exact match.
+ let originalText = token.originalText;
+ if (originalText.startsWith('#')) {
+ originalText = originalText.substr(1);
+ }
+ let term = pattern.term;
+ if (term.startsWith('#')) {
+ term = term.substr(1);
+ }
+
+ if (alias.startsWith('$MM_HASHTAG') && originalText !== term) {
+ continue;
+ }
+
const index = tokens.size + newTokens.size;
const newAlias = `$MM_SEARCHTERM${index}`;
@@ -438,10 +455,10 @@ export function highlightSearchTerms(text, tokens, searchPatterns) {
output = output.replace(alias, newAlias);
}
- // The pattern regexes are global, so calling pattern.test() above alters their
+ // The pattern regexes are global, so calling pattern.pattern.test() above alters their
// state. Reset lastIndex to 0 between calls to test() to ensure it returns the
// same result every time it is called with the same value of token.originalText.
- pattern.lastIndex = 0;
+ pattern.pattern.lastIndex = 0;
}
// the new tokens are stashed in a separate map since we can't add objects to a map during iteration
@@ -449,7 +466,7 @@ export function highlightSearchTerms(text, tokens, searchPatterns) {
tokens.set(newToken[0], newToken[1]);
}
- output = output.replace(pattern, replaceSearchTermWithToken);
+ output = output.replace(pattern.pattern, replaceSearchTermWithToken);
}
return output;
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx
index 0117c3cea..97f56fc4c 100644
--- a/webapp/utils/utils.jsx
+++ b/webapp/utils/utils.jsx
@@ -588,7 +588,7 @@ export function applyTheme(theme) {
if (theme.centerChannelBg) {
changeCss('@media(min-width: 768px){.app__body .post:hover .post__header .col__reply, .app__body .post.post--hovered .post__header .col__reply', 'background:' + theme.centerChannelBg);
changeCss('@media(max-width: 320px){.tutorial-steps__container', 'background:' + theme.centerChannelBg);
- changeCss('.app__body .status-wrapper .status_dropdown__toggle .status .icon__container:after, .app__body .app__content, .app__body .markdown__table, .app__body .markdown__table tbody tr, .app__body .suggestion-list__content, .app__body .modal .modal-content, .app__body .modal .modal-footer, .app__body .post.post--compact .post-image__column, .app__body .suggestion-list__divider > span, .app__body .status-wrapper .status, .app__body .alert.alert-transparent', 'background:' + theme.centerChannelBg);
+ changeCss('.app__body .channel-header__info .channel-header__description:before, .app__body .status-wrapper .status_dropdown__toggle .status .icon__container:after, .app__body .app__content, .app__body .markdown__table, .app__body .markdown__table tbody tr, .app__body .suggestion-list__content, .app__body .modal .modal-content, .app__body .modal .modal-footer, .app__body .post.post--compact .post-image__column, .app__body .suggestion-list__divider > span, .app__body .status-wrapper .status, .app__body .alert.alert-transparent', 'background:' + theme.centerChannelBg);
changeCss('#post-list .post-list-holder-by-time, .app__body .post .dropdown-menu a', 'background:' + theme.centerChannelBg);
changeCss('#post-create', 'background:' + theme.centerChannelBg);
changeCss('.app__body .date-separator .separator__text, .app__body .new-separator .separator__text', 'background:' + theme.centerChannelBg);