fix inline emoji searching speed

master
Aevann 2023-10-27 11:39:33 +03:00
parent e6de1a954e
commit 430be8e9c4
1 changed files with 20 additions and 1 deletions

View File

@ -22,6 +22,7 @@ Copyright (C) 2022 Dr Steven Transmisia, anti-evil engineer,
* @type {"inactive"|"loading"|"ready"}
*/
let emojiEngineState = "inactive";
let emojiSpeedEngineState = "inactive";
// DOM stuff
const classesSelectorDOM = document.getElementById("emoji-modal-tabs");
@ -180,6 +181,8 @@ function makeEmojisSearchDictionary() {
for(let i = 0; i < emoji.tags.length; i++)
emojisSearchDictionary.updateTag(emoji.tags[i], emoji.name);
}
emojiSpeedEngineState = "ready";
})
}
@ -488,7 +491,7 @@ function update_speed_emoji_modal(event)
* kept it unless someone wants to provide an option to toggle it for performance */
if (current_word && curr_word_is_emoji() && current_word != ":")
{
makeEmojisSearchDictionary().then( () => {
openSpeedModal().then( () => {
let modal_pos = event.target.getBoundingClientRect();
modal_pos.x += window.scrollX;
modal_pos.y += window.scrollY;
@ -592,6 +595,22 @@ function openEmojiModal(t, inputTargetIDName)
}
}
function openSpeedModal()
{
switch (emojiSpeedEngineState) {
case "inactive":
emojiSpeedEngineState = "loading"
return makeEmojisSearchDictionary();
case "loading":
// this works because once the fetch completes, the first keystroke callback will fire and use the current value
return Promise.reject();
case "ready":
return Promise.resolve();
default:
throw Error("Unknown emoji engine state");
}
}
document.getElementById('emojiModal').addEventListener('shown.bs.modal', function () {
focusSearchBar(emojiSearchBarDOM);
setTimeout(() => {