From 878f0a4753a9c57d0f7dc671e04b1fd7d8e87d7f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 6 Jun 2019 08:39:24 +0100 Subject: [PATCH 1/2] Be somewhat fuzzier when matching emojis to complete on space Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/rooms/MessageComposerInput.js | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index a525fcb874..b3b71a0e52 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -533,21 +533,26 @@ export default class MessageComposerInput extends React.Component { // The first matched group includes just the matched plaintext emoji const emoticonMatch = REGEX_EMOTICON_WHITESPACE.exec(text.slice(0, currentStartOffset)); if (emoticonMatch) { - const data = EMOJIBASE.find(e => e.emoticon === emoticonMatch[1]); - const unicodeEmoji = data ? data.unicode : ''; - - const range = Range.create({ - anchor: { - key: editorState.startText.key, - offset: currentStartOffset - emoticonMatch[1].length - 1, - }, - focus: { - key: editorState.startText.key, - offset: currentStartOffset - 1, - }, + const data = EMOJIBASE.find(e => { + if (!e.emoticon) return false; + return e.emoticon.toLowerCase() === emoticonMatch[1].toLowerCase().replace("-", ""); }); - change = change.insertTextAtRange(range, unicodeEmoji); - editorState = change.value; + + // only perform replacement if we found a match, otherwise we would be not letting user type + if (data) { + const range = Range.create({ + anchor: { + key: editorState.startText.key, + offset: currentStartOffset - emoticonMatch[1].length - 1, + }, + focus: { + key: editorState.startText.key, + offset: currentStartOffset - 1, + }, + }); + change = change.insertTextAtRange(range, data.unicode); + editorState = change.value; + } } } } From 25a994e5758812140897ab6801a130bd61508837 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 6 Jun 2019 08:45:32 +0100 Subject: [PATCH 2/2] pull toLowerCase(...).replace(...) out of the loop Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/rooms/MessageComposerInput.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index b3b71a0e52..939ec4d9f5 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -533,10 +533,8 @@ export default class MessageComposerInput extends React.Component { // The first matched group includes just the matched plaintext emoji const emoticonMatch = REGEX_EMOTICON_WHITESPACE.exec(text.slice(0, currentStartOffset)); if (emoticonMatch) { - const data = EMOJIBASE.find(e => { - if (!e.emoticon) return false; - return e.emoticon.toLowerCase() === emoticonMatch[1].toLowerCase().replace("-", ""); - }); + const query = emoticonMatch[1].toLowerCase().replace("-", ""); + const data = EMOJIBASE.find(e => e.emoticon ? e.emoticon.toLowerCase() === query : false); // only perform replacement if we found a match, otherwise we would be not letting user type if (data) {