Skip to content

Commit

Permalink
fix: speed up emoji parsing and replacements
Browse files Browse the repository at this point in the history
extract the invariant/const parts out of the inner loop
(`emojiJSON.emoji_json.filter`); greatly speeds up typing speed
  • Loading branch information
caybro committed Apr 7, 2023
1 parent 5dbc08d commit c8877aa
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ui/imports/shared/status/StatusChatInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,14 +1292,16 @@ Rectangle {

onTextChanged: {
if (length <= control.messageLimit) {
var symbols = ":='xX><0O;*dB8-D#%\\";
var symbolIdx = ((cursorPosition > 2) && (symbols.indexOf(getText((cursorPosition - 2), (cursorPosition - 1)))!==-1))
const symbols = ":='xX><0O;*dB8-D#%\\";
const symbolIdx = ((cursorPosition > 2) && (symbols.indexOf(getText((cursorPosition - 2), (cursorPosition - 1)))!==-1))
? (cursorPosition -1) : (symbols.indexOf(getText(0, 1))!==-1) ? 2 : -1;
if ((getText(symbolIdx-2, (symbolIdx-1)) === " ") || (symbolIdx === 2)) {
const textBefore1 = getText((symbolIdx-1), (symbolIdx+1))
const textBefore2 = getText((symbolIdx-2), (symbolIdx+1))
const has2CharsText = getText((symbolIdx-4), (symbolIdx-2))
const emojis = StatusQUtils.Emoji.emojiJSON.emoji_json.filter(function (emoji) {
if (emoji.aliases_ascii.includes(getText((symbolIdx-1), (symbolIdx+1))) ||
emoji.aliases_ascii.includes(getText((symbolIdx-2), (symbolIdx+1)))) {
var has2Chars = emoji.aliases_ascii.includes(getText((symbolIdx-4), (symbolIdx-2)));
if (emoji.aliases_ascii.includes(textBefore1) || emoji.aliases_ascii.includes(textBefore2)) {
const has2Chars = emoji.aliases_ascii.includes(has2CharsText)
replaceWithEmoji("", getText((symbolIdx - (has2Chars ? 3 : 2)), symbolIdx), emoji.unicode);
}
})
Expand All @@ -1308,7 +1310,7 @@ Rectangle {
mentionsPos = [];
}
} else {
var removeFrom = (cursorPosition < messageLimit) ? cursorWhenPressed : messageLimit;
const removeFrom = (cursorPosition < messageLimit) ? cursorWhenPressed : messageLimit;
remove(removeFrom, cursorPosition);
}

Expand Down

0 comments on commit c8877aa

Please # to comment.