diff options
Diffstat (limited to 'webapp/components/suggestion/emoticon_provider.jsx')
-rw-r--r-- | webapp/components/suggestion/emoticon_provider.jsx | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/webapp/components/suggestion/emoticon_provider.jsx b/webapp/components/suggestion/emoticon_provider.jsx index c2b6b9a50..d04750159 100644 --- a/webapp/components/suggestion/emoticon_provider.jsx +++ b/webapp/components/suggestion/emoticon_provider.jsx @@ -46,20 +46,23 @@ export default class EmoticonProvider { handlePretextChanged(suggestionId, pretext) { let hasSuggestions = false; - // look for partial matches among the named emojis - const captured = (/(?:^|\s)(:([^:\s]*))$/g).exec(pretext); + // look for the potential emoticons at the start of the text, after whitespace, and at the start of emoji reaction commands + const captured = (/(^|\s|^\+|^-)(:([^:\s]*))$/g).exec(pretext); if (captured) { - const text = captured[1]; - const partialName = captured[2]; + const prefix = captured[1]; + const text = captured[2]; + const partialName = captured[3]; const matched = []; - // check for text emoticons - for (const emoticon of Object.keys(Emoticons.emoticonPatterns)) { - if (Emoticons.emoticonPatterns[emoticon].test(text)) { - SuggestionStore.addSuggestion(suggestionId, text, EmojiStore.get(emoticon), EmoticonSuggestion, text); + // check for text emoticons if this isn't for an emoji reaction + if (prefix !== '-' && prefix !== '+') { + for (const emoticon of Object.keys(Emoticons.emoticonPatterns)) { + if (Emoticons.emoticonPatterns[emoticon].test(text)) { + SuggestionStore.addSuggestion(suggestionId, text, EmojiStore.get(emoticon), EmoticonSuggestion, text); - hasSuggestions = true; + hasSuggestions = true; + } } } @@ -76,11 +79,14 @@ export default class EmoticonProvider { // sort the emoticons so that emoticons starting with the entered text come first matched.sort((a, b) => { - const aPrefix = a.name.startsWith(partialName); - const bPrefix = b.name.startsWith(partialName); + const aName = a.name || a.aliases[0]; + const bName = b.name || b.aliases[0]; + + const aPrefix = aName.startsWith(partialName); + const bPrefix = bName.startsWith(partialName); if (aPrefix === bPrefix) { - return a.name.localeCompare(b.name); + return aName.localeCompare(bName); } else if (aPrefix) { return -1; } @@ -88,7 +94,7 @@ export default class EmoticonProvider { return 1; }); - const terms = matched.map((emoticon) => ':' + emoticon.name + ':'); + const terms = matched.map((emoticon) => ':' + (emoticon.name || emoticon.aliases[0]) + ':'); SuggestionStore.clearSuggestions(suggestionId); if (terms.length > 0) { |