diff options
author | Joram Wilander <jwawilander@gmail.com> | 2015-12-08 11:51:52 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2015-12-08 11:51:52 -0500 |
commit | 17788fb47f54b40c4ab7b17a5f7b7e62406a64f5 (patch) | |
tree | 16de9a6b5f17aca16ed7d4bd2a81973cdaf1c489 /web/react/components/suggestion/emoticon_provider.jsx | |
parent | e2fc28b1f36f8be8a0631d78e21693fb3fd2947f (diff) | |
parent | 47c51dbcf0f380931875b8ebf8ec2f343af9b3ba (diff) | |
download | chat-17788fb47f54b40c4ab7b17a5f7b7e62406a64f5.tar.gz chat-17788fb47f54b40c4ab7b17a5f7b7e62406a64f5.tar.bz2 chat-17788fb47f54b40c4ab7b17a5f7b7e62406a64f5.zip |
Merge pull request #1654 from hmhealey/plt1421
PLT-1421 Changed ordering of emoticon suggestions
Diffstat (limited to 'web/react/components/suggestion/emoticon_provider.jsx')
-rw-r--r-- | web/react/components/suggestion/emoticon_provider.jsx | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/web/react/components/suggestion/emoticon_provider.jsx b/web/react/components/suggestion/emoticon_provider.jsx index 7dcb86442..fd470cf21 100644 --- a/web/react/components/suggestion/emoticon_provider.jsx +++ b/web/react/components/suggestion/emoticon_provider.jsx @@ -51,23 +51,40 @@ export default class EmoticonProvider { const text = captured[1]; const partialName = captured[2]; - const terms = []; const names = []; for (const emoticon of Emoticons.emoticonMap.keys()) { if (emoticon.indexOf(partialName) !== -1) { - terms.push(':' + emoticon + ':'); names.push(emoticon); - if (terms.length >= MAX_EMOTICON_SUGGESTIONS) { + if (names.length >= MAX_EMOTICON_SUGGESTIONS) { break; } } } + // sort the emoticons so that emoticons starting with the entered text come first + names.sort((a, b) => { + const aPrefix = a.startsWith(partialName); + const bPrefix = b.startsWith(partialName); + + if (aPrefix === bPrefix) { + return a.localeCompare(b); + } else if (aPrefix) { + return -1; + } + + return 1; + }); + + const terms = names.map((name) => ':' + name + ':'); + if (terms.length > 0) { SuggestionStore.setMatchedPretext(suggestionId, text); SuggestionStore.addSuggestions(suggestionId, terms, names, EmoticonSuggestion); + + // force the selection to be cleared since the order of elements may have changed + SuggestionStore.clearSelection(suggestionId); } } } |