diff options
-rw-r--r-- | webapp/components/suggestion/emoticon_provider.jsx | 27 | ||||
-rw-r--r-- | webapp/utils/emoticons.jsx | 2 |
2 files changed, 24 insertions, 5 deletions
diff --git a/webapp/components/suggestion/emoticon_provider.jsx b/webapp/components/suggestion/emoticon_provider.jsx index e2ed7978d..7a45c5b4e 100644 --- a/webapp/components/suggestion/emoticon_provider.jsx +++ b/webapp/components/suggestion/emoticon_provider.jsx @@ -43,14 +43,29 @@ class EmoticonSuggestion extends Suggestion { export default class EmoticonProvider { handlePretextChanged(suggestionId, pretext) { - const captured = (/(?:^|\s)(:([a-zA-Z0-9_+\-]*))$/g).exec(pretext); + let hasSuggestions = false; + + // look for partial matches among the named emojis + const captured = (/(?:^|\s)(:([^:\s]*))$/g).exec(pretext); if (captured) { const text = captured[1]; const partialName = captured[2]; const matched = []; - for (const [name, emoticon] of Emoticons.getEmoticonsByName()) { + const emoticons = Emoticons.getEmoticonsByName(); + + // check for text emoticons + for (const emoticon of Object.keys(Emoticons.emoticonPatterns)) { + if (Emoticons.emoticonPatterns[emoticon].test(text)) { + SuggestionStore.addSuggestion(suggestionId, text, emoticons.get(emoticon), EmoticonSuggestion, text); + + hasSuggestions = true; + } + } + + // checked for named emoji + for (const [name, emoticon] of emoticons) { if (name.indexOf(partialName) !== -1) { matched.push(emoticon); @@ -79,9 +94,13 @@ export default class EmoticonProvider { if (terms.length > 0) { SuggestionStore.addSuggestions(suggestionId, terms, matched, EmoticonSuggestion, text); - // force the selection to be cleared since the order of elements may have changed - SuggestionStore.clearSelection(suggestionId); + hasSuggestions = true; } } + + if (hasSuggestions) { + // force the selection to be cleared since the order of elements may have changed + SuggestionStore.clearSelection(suggestionId); + } } } diff --git a/webapp/utils/emoticons.jsx b/webapp/utils/emoticons.jsx index 58057a187..1f3fdff8e 100644 --- a/webapp/utils/emoticons.jsx +++ b/webapp/utils/emoticons.jsx @@ -4,7 +4,7 @@ import Constants from './constants.jsx'; import emojis from './emoji.json'; -const emoticonPatterns = { +export const emoticonPatterns = { slightly_smiling_face: /(^|\s)(:-?\))(?=$|\s)/g, // :) wink: /(^|\s)(;-?\))(?=$|\s)/g, // ;) open_mouth: /(^|\s)(:o)(?=$|\s)/gi, // :o |