From 438b63bee27860c71b22ed5f4cc0e059dd002057 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 1 Aug 2017 14:26:30 +0100 Subject: [PATCH] Only auto-replace emoji following ^ or \s So as not to cause issues when typing e.g. `This is what was tested: ` (the "d:" used to be transformed into an emoji) --- src/components/views/rooms/MessageComposerInput.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 50486047a5..5045a47d67 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -50,7 +50,7 @@ const REGEX_MATRIXTO_MARKDOWN_GLOBAL = new RegExp(MATRIXTO_MD_LINK_PATTERN, 'g') import {asciiRegexp, shortnameToUnicode, emojioneList, asciiList, mapUnicodeToShort} from 'emojione'; const EMOJI_SHORTNAMES = Object.keys(emojioneList); const EMOJI_UNICODE_TO_SHORTNAME = mapUnicodeToShort(); -const REGEX_EMOJI_WHITESPACE = new RegExp('(' + asciiRegexp + ')\\s$'); +const REGEX_EMOJI_WHITESPACE = new RegExp('(?:^|\\s)(' + asciiRegexp + ')\\s$'); const TYPING_USER_TIMEOUT = 10000, TYPING_SERVER_TIMEOUT = 30000; @@ -393,7 +393,7 @@ export default class MessageComposerInput extends React.Component { const newContentState = Modifier.replaceText( editorState.getCurrentContent(), currentSelection.merge({ - anchorOffset: currentStartOffset - emojiMatch[0].length, + anchorOffset: currentStartOffset - emojiMatch[1].length - 1, focusOffset: currentStartOffset, }), unicodeEmoji,