From 577dbba8317fbbe57cac7912c34bf45448a43bba Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 28 Sep 2020 11:23:04 -0400 Subject: [PATCH] fix: fix code review and fix deleting colon closes emoji popup --- .../AppLayouts/Chat/ChatColumn/ChatInput.qml | 20 +++++++------------ .../AppLayouts/Chat/components/EmojiPopup.qml | 2 +- ui/imports/Emoji.qml | 10 ++++++++++ ui/imports/Utils.qml | 10 ++-------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml index 89d58e05d4..1c955bcb09 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml @@ -111,7 +111,7 @@ Rectangle { var transform = true; if (words[i].charAt(0) === ':') { for (var j = 0; j < words[i].length; j++) { - if (isSpace(words[i].charAt(j)) === true || Utils.isPunct(words[i].charAt(j)) === true) { + if (Utils.isSpace(words[i].charAt(j)) === true || Utils.isPunct(words[i].charAt(j)) === true) { transform = false; } } @@ -128,10 +128,10 @@ Rectangle { } function replaceWithEmoji(message, shortname, codePoint) { - const encodedCodePoint = Utils.getEmojiCodepoint(codePoint) + const encodedCodePoint = Emoji.getEmojiCodepoint(codePoint) const newMessage = message.data - .replace(shortname, encodedCodePoint) - .replace(/ /g, " "); + .replace(shortname, encodedCodePoint) + .replace(/ /g, " "); txtData.remove(0, txtData.cursorPosition); insertInTextInput(0, Emoji.parse(newMessage, '26x26')); emojiSuggestions.close() @@ -144,7 +144,7 @@ Rectangle { // state machine to handle different forms of the emoji event state if (!emojiEvent && isColonPressed) { - return (message.data.length <= 1 || isSpace(message.data.charAt(message.cursor - 1))) ? true : false; + return (message.data.length <= 1 || Utils.isSpace(message.data.charAt(message.cursor - 1))) ? true : false; } else if (emojiEvent && isColonPressed) { const index = message.data.lastIndexOf(':', message.cursor - 2); if (index >= 0 && message.cursor > 0) { @@ -170,8 +170,8 @@ Rectangle { emojiSuggestions.openPopup(emojis, emojiPart) } + return true; } - return true; } else if (emojiEvent && !isKeyValid(event.key) && !isColonPressed) { return false; } @@ -237,7 +237,7 @@ Rectangle { function validSubstr(substr) { for(var i = 0; i < substr.length; i++) { var c = substr.charAt(i); - if (c !== '_' && (isSpace(c) === true || Utils.isPunct(c) === true)) { + if (c !== '_' && (Utils.isSpace(c) === true || Utils.isPunct(c) === true)) { return false; } } @@ -254,12 +254,6 @@ Rectangle { return true; } - function isSpace(c) { - if (/( |\t|\n|\r)/.test(c)) - return true; - return false; - } - FileDialog { id: imageDialog //% "Please choose an image" diff --git a/ui/app/AppLayouts/Chat/components/EmojiPopup.qml b/ui/app/AppLayouts/Chat/components/EmojiPopup.qml index 778bf5da99..5b03e3d135 100644 --- a/ui/app/AppLayouts/Chat/components/EmojiPopup.qml +++ b/ui/app/AppLayouts/Chat/components/EmojiPopup.qml @@ -40,7 +40,7 @@ Popup { iconCodePoint = iconCodePoint.substring(0, extenstionIndex) } - const encodedIcon = Utils.getEmojiCodepoint(iconCodePoint) + const encodedIcon = Emoji.getEmojiCodepoint(iconCodePoint) // Add at the start of the list let recentEmojis = appSettings.recentEmojis diff --git a/ui/imports/Emoji.qml b/ui/imports/Emoji.qml index 5b6c5cf83f..d91487421d 100644 --- a/ui/imports/Emoji.qml +++ b/ui/imports/Emoji.qml @@ -39,4 +39,14 @@ QtObject { return _emoji.unicode; return undefined; } + + function getEmojiCodepoint(iconCodePoint) { + // Split the codepoint to get all the parts and then encode them from hex to utf8 + const splitCodePoint = iconCodePoint.split('-') + let codePointParts = [] + splitCodePoint.forEach(function (codePoint) { + codePointParts.push(`0x${codePoint}`) + }) + return String.fromCodePoint(...codePointParts); + } } diff --git a/ui/imports/Utils.qml b/ui/imports/Utils.qml index cb43bb54aa..5141841cb1 100644 --- a/ui/imports/Utils.qml +++ b/ui/imports/Utils.qml @@ -140,14 +140,8 @@ QtObject { } } - function getEmojiCodepoint(iconCodePoint) { - // Split the codepoint to get all the parts and then encode them from hex to utf8 - const splitCodePoint = iconCodePoint.split('-') - let codePointParts = [] - splitCodePoint.forEach(function (codePoint) { - codePointParts.push(`0x${codePoint}`) - }) - return String.fromCodePoint(...codePointParts); + function isSpace(c) { + return (/( |\t|\n|\r)/.test(c)) } function isPunct(c) {