fix: fix code review and fix deleting colon closes emoji popup

This commit is contained in:
Jonathan Rainville 2020-09-28 11:23:04 -04:00 committed by Iuri Matias
parent db6b87d813
commit 577dbba831
4 changed files with 20 additions and 22 deletions

View File

@ -111,7 +111,7 @@ Rectangle {
var transform = true; var transform = true;
if (words[i].charAt(0) === ':') { if (words[i].charAt(0) === ':') {
for (var j = 0; j < words[i].length; j++) { 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; transform = false;
} }
} }
@ -128,10 +128,10 @@ Rectangle {
} }
function replaceWithEmoji(message, shortname, codePoint) { function replaceWithEmoji(message, shortname, codePoint) {
const encodedCodePoint = Utils.getEmojiCodepoint(codePoint) const encodedCodePoint = Emoji.getEmojiCodepoint(codePoint)
const newMessage = message.data const newMessage = message.data
.replace(shortname, encodedCodePoint) .replace(shortname, encodedCodePoint)
.replace(/ /g, "&nbsp;"); .replace(/ /g, "&nbsp;");
txtData.remove(0, txtData.cursorPosition); txtData.remove(0, txtData.cursorPosition);
insertInTextInput(0, Emoji.parse(newMessage, '26x26')); insertInTextInput(0, Emoji.parse(newMessage, '26x26'));
emojiSuggestions.close() emojiSuggestions.close()
@ -144,7 +144,7 @@ Rectangle {
// state machine to handle different forms of the emoji event state // state machine to handle different forms of the emoji event state
if (!emojiEvent && isColonPressed) { 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) { } else if (emojiEvent && isColonPressed) {
const index = message.data.lastIndexOf(':', message.cursor - 2); const index = message.data.lastIndexOf(':', message.cursor - 2);
if (index >= 0 && message.cursor > 0) { if (index >= 0 && message.cursor > 0) {
@ -170,8 +170,8 @@ Rectangle {
emojiSuggestions.openPopup(emojis, emojiPart) emojiSuggestions.openPopup(emojis, emojiPart)
} }
return true;
} }
return true;
} else if (emojiEvent && !isKeyValid(event.key) && !isColonPressed) { } else if (emojiEvent && !isKeyValid(event.key) && !isColonPressed) {
return false; return false;
} }
@ -237,7 +237,7 @@ Rectangle {
function validSubstr(substr) { function validSubstr(substr) {
for(var i = 0; i < substr.length; i++) { for(var i = 0; i < substr.length; i++) {
var c = substr.charAt(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; return false;
} }
} }
@ -254,12 +254,6 @@ Rectangle {
return true; return true;
} }
function isSpace(c) {
if (/( |\t|\n|\r)/.test(c))
return true;
return false;
}
FileDialog { FileDialog {
id: imageDialog id: imageDialog
//% "Please choose an image" //% "Please choose an image"

View File

@ -40,7 +40,7 @@ Popup {
iconCodePoint = iconCodePoint.substring(0, extenstionIndex) iconCodePoint = iconCodePoint.substring(0, extenstionIndex)
} }
const encodedIcon = Utils.getEmojiCodepoint(iconCodePoint) const encodedIcon = Emoji.getEmojiCodepoint(iconCodePoint)
// Add at the start of the list // Add at the start of the list
let recentEmojis = appSettings.recentEmojis let recentEmojis = appSettings.recentEmojis

View File

@ -39,4 +39,14 @@ QtObject {
return _emoji.unicode; return _emoji.unicode;
return undefined; 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);
}
} }

View File

@ -140,14 +140,8 @@ QtObject {
} }
} }
function getEmojiCodepoint(iconCodePoint) { function isSpace(c) {
// Split the codepoint to get all the parts and then encode them from hex to utf8 return (/( |\t|\n|\r)/.test(c))
const splitCodePoint = iconCodePoint.split('-')
let codePointParts = []
splitCodePoint.forEach(function (codePoint) {
codePointParts.push(`0x${codePoint}`)
})
return String.fromCodePoint(...codePointParts);
} }
function isPunct(c) { function isPunct(c) {