diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-08-12 07:49:19 -0400 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-08-12 07:49:19 -0400 |
commit | c0a905c0376014763f851405032d2ae5440b45da (patch) | |
tree | dc6ad11a67843fd0020083b9ed841d2c8704f04a /webapp | |
parent | 96420542b193defc6a562d2151acf113ef93b87f (diff) | |
download | chat-c0a905c0376014763f851405032d2ae5440b45da.tar.gz chat-c0a905c0376014763f851405032d2ae5440b45da.tar.bz2 chat-c0a905c0376014763f851405032d2ae5440b45da.zip |
PLT-1424 Added XRegExp library to fix search highlighting (#3787)
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/package.json | 3 | ||||
-rw-r--r-- | webapp/utils/text_formatting.jsx | 15 |
2 files changed, 8 insertions, 10 deletions
diff --git a/webapp/package.json b/webapp/package.json index d68223408..dce79447a 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -31,7 +31,8 @@ "react-textarea-autosize": "4.0.3", "superagent": "2.1.0", "twemoji": "2.0.5", - "velocity-animate": "1.2.3" + "velocity-animate": "1.2.3", + "xregexp": "3.1.1" }, "devDependencies": { "babel-core": "6.13.2", diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx index 655b4180e..c110fc52f 100644 --- a/webapp/utils/text_formatting.jsx +++ b/webapp/utils/text_formatting.jsx @@ -11,6 +11,7 @@ import PreferenceStore from 'stores/preference_store.jsx'; import UserStore from 'stores/user_store.jsx'; import twemoji from 'twemoji'; import * as Utils from './utils.jsx'; +import XRegExp from 'xregexp'; // pattern to detect the existance of a Chinese, Japanese, or Korean character in a string // http://stackoverflow.com/questions/15033196/using-javascript-to-check-whether-a-string-contains-japanese-characters-includi @@ -140,13 +141,9 @@ function autolinkEmails(text, tokens) { return autolinker.link(text); } -function autolinkAtMentions(text, tokens) { - // Return true if provided character is punctuation - function isPunctuation(character) { - const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g; - return re.test(character); - } +const punctuation = XRegExp.cache('[^\\pL\\d]'); +function autolinkAtMentions(text, tokens) { // Test if provided text needs to be highlighted, special mention or current user function mentionExists(u) { return (Constants.SPECIAL_MENTIONS.indexOf(u) !== -1 || UserStore.getProfileByUsername(u)); @@ -176,7 +173,7 @@ function autolinkAtMentions(text, tokens) { const originalUsername = usernameLower; for (let c = usernameLower.length; c > 0; c--) { - if (isPunctuation(usernameLower[c - 1])) { + if (punctuation.test(usernameLower[c - 1])) { usernameLower = usernameLower.substring(0, c - 1); if (mentionExists(usernameLower)) { @@ -299,8 +296,8 @@ function autolinkHashtags(text, tokens) { return output.replace(/(^|\W)(#[a-zA-ZäöüÄÖÜß][a-zA-Z0-9äöüÄÖÜß.\-_]*)\b/g, replaceHashtagWithToken); } -const puncStart = /^[^a-zA-Z0-9#]+/; -const puncEnd = /[^a-zA-Z0-9]+$/; +const puncStart = XRegExp.cache('^[^\\pL\\d\\s#]+'); +const puncEnd = XRegExp.cache('[^\\pL\\d\\s]+$'); function parseSearchTerms(searchTerm) { let terms = []; |