Be somewhat fuzzier when matching emojis to complete on space

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2019-06-06 08:39:24 +01:00
parent 97019fbfb5
commit 878f0a4753

View File

@ -533,9 +533,13 @@ 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 data = EMOJIBASE.find(e => {
if (!e.emoticon) return false;
return e.emoticon.toLowerCase() === emoticonMatch[1].toLowerCase().replace("-", "");
});
// 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,
@ -546,11 +550,12 @@ export default class MessageComposerInput extends React.Component {
offset: currentStartOffset - 1,
},
});
change = change.insertTextAtRange(range, unicodeEmoji);
change = change.insertTextAtRange(range, data.unicode);
editorState = change.value;
}
}
}
}
if (this.props.onInputStateChanged && editorState.blocks.size > 0) {
let blockType = editorState.blocks.first().type;