From 40b2a5c778a09e5a9089cd68efbb8a8cce9de9c7 Mon Sep 17 00:00:00 2001 From: Alexandra Betouni Date: Fri, 9 Jul 2021 19:11:17 +0300 Subject: [PATCH] [#1608] convert text to emoji automatically MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example, typing :D should turn into 😁 Closes #1608 --- ui/shared/status/StatusChatInput.qml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ui/shared/status/StatusChatInput.qml b/ui/shared/status/StatusChatInput.qml index e182dbfb86..1376f9b76c 100644 --- a/ui/shared/status/StatusChatInput.qml +++ b/ui/shared/status/StatusChatInput.qml @@ -871,11 +871,21 @@ Rectangle { Keys.onReleased: onRelease(event) // gives much more up to date cursorPosition Keys.onShortcutOverride: event.accepted = isUploadFilePressed(event) leftPadding: 0 - background: Rectangle { - color: "transparent" - } selectionColor: Style.current.primarySelectionColor persistentSelection: true + onTextChanged: { + var symbols = ":='xX><0O;*dB8-D#%\\"; + if ((length > 1) && (symbols.indexOf(getText((cursorPosition - 2), (cursorPosition - 1))) !== -1)) { + const emojis = EmojiJSON.emoji_json.filter(function (emoji) { + if (emoji.aliases_ascii.includes(getText((cursorPosition - 2), cursorPosition)) || + emoji.aliases_ascii.includes(getText((cursorPosition - 3), cursorPosition))) { + var has2Chars = emoji.aliases_ascii.includes(getText((cursorPosition - 2), cursorPosition)); + replaceWithEmoji("", getText(cursorPosition - (has2Chars ? 2 : 3), cursorPosition), emoji.unicode); + } + }) + } + } + onReleased: function (event) { const now = Date.now() if (messageInputField.selectedText.trim() !== "") {