Compare commits

...

4 Commits

Author SHA1 Message Date
easrng 048af96a19 Merge branch 'main' of lavender.software:lavender/watch-party 2022-02-18 14:22:01 -05:00
easrng ae87f2abe0 actually fix perf 2022-02-18 14:21:54 -05:00
easrng 98e1393441 tweak append stuff 2022-02-18 14:11:54 -05:00
easrng 7b1defe010 yield between appending 100 item chunks 2022-02-18 14:04:55 -05:00
1 changed files with 50 additions and 37 deletions

View File

@ -45,7 +45,7 @@ const setupChatboxEvents = (socket) => {
const search = text.slice(match.index + 1); const search = text.slice(match.index + 1);
if (search.length < 1 && !fromListTimeout) { if (search.length < 1 && !fromListTimeout) {
autocompleting = false; autocompleting = false;
showListTimer = setTimeout(() => autocomplete(true), 1000); showListTimer = setTimeout(() => autocomplete(true), 500);
return; return;
} }
const suffix = messageInput.value.slice(messageInput.selectionStart); const suffix = messageInput.value.slice(messageInput.selectionStart);
@ -55,42 +55,55 @@ const setupChatboxEvents = (socket) => {
selected = button; selected = button;
button.classList.add("selected"); button.classList.add("selected");
}; };
emojiAutocomplete.append( let results = await findEmojis(search);
...(await findEmojis(search)).map(([name, replaceWith, ext], i) => { let yieldAt = performance.now() + 13;
const button = Object.assign(document.createElement("button"), { for (let i = 0; i < results.length; i += 100) {
className: "emoji-option", emojiAutocomplete.append.apply(
onmousedown: (e) => e.preventDefault(), emojiAutocomplete,
onclick: () => { results.slice(i, i + 100).map(([name, replaceWith, ext], i) => {
messageInput.value = prefix + replaceWith + " " + suffix; const button = Object.assign(document.createElement("button"), {
setCaretPosition(messageInput, (prefix + " " + replaceWith).length); className: "emoji-option",
}, onmousedown: (e) => e.preventDefault(),
onmouseover: () => select(button), onclick: () => {
onfocus: () => select(button), messageInput.value = prefix + replaceWith + " " + suffix;
type: "button", setCaretPosition(
title: name, messageInput,
}); (prefix + " " + replaceWith).length
button.append( );
replaceWith[0] !== ":" },
? Object.assign(document.createElement("span"), { onmouseover: () => select(button),
textContent: replaceWith, onfocus: () => select(button),
className: "emoji", type: "button",
}) title: name,
: Object.assign(new Image(), { });
loading: "lazy", button.append(
src: `/emojis/${name}${ext}`, replaceWith[0] !== ":"
className: "emoji", ? Object.assign(document.createElement("span"), {
}), textContent: replaceWith,
Object.assign(document.createElement("span"), { className: "emoji",
textContent: name, })
className: "emoji-name", : Object.assign(new Image(), {
}) loading: "lazy",
); src: `/emojis/${name}${ext}`,
return button; className: "emoji",
}) }),
); Object.assign(document.createElement("span"), {
if (emojiAutocomplete.children[0]) { textContent: name,
emojiAutocomplete.children[0].scrollIntoView(); className: "emoji-name",
select(emojiAutocomplete.children[0]); })
);
return button;
})
);
if (i == 0 && emojiAutocomplete.children[0]) {
emojiAutocomplete.children[0].scrollIntoView();
select(emojiAutocomplete.children[0]);
}
const now = performance.now();
if (now > yieldAt) {
yieldAt = now + 13;
await new Promise((cb) => setTimeout(cb, 0));
}
} }
autocompleting = false; autocompleting = false;
} }