tweak append stuff

easrng 2022-02-18 14:11:54 -05:00
parent 7b1defe010
commit 98e1393441
1 changed files with 7 additions and 2 deletions

View File

@ -56,7 +56,8 @@ const setupChatboxEvents = (socket) => {
button.classList.add("selected"); button.classList.add("selected");
}; };
let results = await findEmojis(search); let results = await findEmojis(search);
for (let i = 0; i < results.length; i += 100) { let yieldAt = performance.now() + 13;
for (let i = 0; i < results.length; i += 10) {
emojiAutocomplete.append.apply( emojiAutocomplete.append.apply(
emojiAutocomplete, emojiAutocomplete,
results.slice(i, i + 1000).map(([name, replaceWith, ext], i) => { results.slice(i, i + 1000).map(([name, replaceWith, ext], i) => {
@ -98,8 +99,12 @@ const setupChatboxEvents = (socket) => {
emojiAutocomplete.children[0].scrollIntoView(); emojiAutocomplete.children[0].scrollIntoView();
select(emojiAutocomplete.children[0]); select(emojiAutocomplete.children[0]);
} }
const now = performance.now();
if (now > yieldAt) {
yieldAt = now + 13;
await new Promise((cb) => setTimeout(cb, 0)); await new Promise((cb) => setTimeout(cb, 0));
} }
}
autocompleting = false; autocompleting = false;
} }
messageInput.addEventListener("input", () => autocomplete()); messageInput.addEventListener("input", () => autocomplete());