From 8531c83574fc73a729f04cc7eeb8e045f54aa8f1 Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Fri, 29 Apr 2022 23:22:23 +0100 Subject: [PATCH] Sort unicode emoji before emojos, let enter fill an emoji --- frontend/lib/chat.mjs | 6 +++--- frontend/lib/emojis.mjs | 20 ++++++++++---------- src/main.rs | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frontend/lib/chat.mjs b/frontend/lib/chat.mjs index 1dc0ae8..63b5641 100644 --- a/frontend/lib/chat.mjs +++ b/frontend/lib/chat.mjs @@ -6,7 +6,7 @@ import { import { emojify, findEmojis } from "./emojis.mjs?v=ee93fb"; import { linkify } from "./links.mjs?v=ee93fb"; import { joinSession } from "./watch-session.mjs?v=ee93fb"; -import { pling } from "./pling.mjs?v=ee93fb" +import { pling } from "./pling.mjs?v=ee93fb"; import { state } from "./state.mjs"; function setCaretPosition(elem, caretPos) { @@ -44,7 +44,7 @@ const setupChatboxEvents = (socket) => { emojiAutocomplete.textContent = ""; autocompleting = true; let text = messageInput.value.slice(0, messageInput.selectionStart); - const match = text.match(/(:[^\s:]+)?:([^\s:]*)$/); + const match = text.match(/(:[^\s:]+)?:([^\s:]{2,})$/); if (!match || match[1]) return (autocompleting = false); // We don't need to autocomplete. const prefix = text.slice(0, match.index); const search = text.slice(match.index + 1); @@ -133,7 +133,7 @@ const setupChatboxEvents = (socket) => { selected.classList.add("selected"); selected.scrollIntoView({ scrollMode: "if-needed", block: "nearest" }); } - if (event.key == "Tab") { + if (event.key == "Tab" || event.key == "Enter") { let selected = document.querySelector(".emoji-option.selected"); if (!selected) return; event.preventDefault(); diff --git a/frontend/lib/emojis.mjs b/frontend/lib/emojis.mjs index d05eede..ba2ec3c 100644 --- a/frontend/lib/emojis.mjs +++ b/frontend/lib/emojis.mjs @@ -32,7 +32,15 @@ export async function emojify(text) { const emojis = {}; export const emojisLoaded = Promise.all([ - fetch("/emojis") + fetch("/emojis/unicode.json") + .then((e) => e.json()) + .then((a) => { + for (let e of a) { + emojis[e[0][0]] = emojis[e[0][0]] || []; + emojis[e[0][0]].push([e[0], e[1], null, e[0]]); + } + }), + fetch("/emojos") .then((e) => e.json()) .then((a) => { for (let e of a) { @@ -42,14 +50,6 @@ export const emojisLoaded = Promise.all([ emojis[lower[0]].push([name, ":" + name + ":", e.slice(-4), lower]); } }), - fetch("/emojis/unicode.json") - .then((e) => e.json()) - .then((a) => { - for (let e of a) { - emojis[e[0][0]] = emojis[e[0][0]] || []; - emojis[e[0][0]].push([e[0], e[1], null, e[0]]); - } - }), ]); export async function findEmojis(search) { @@ -68,5 +68,5 @@ export async function findEmojis(search) { } } } - return [...groups[0], ...groups[1]]; + return [...groups[1], ...groups[0]]; } diff --git a/src/main.rs b/src/main.rs index cda5b41..9d29e35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,7 @@ async fn main() { warb::reply::json(&json!({ "id": session_uuid.to_string(), "session": session_view })) }); - let get_emoji_route = warb::path!("emojis").and_then(get_emoji_list); + let get_emoji_route = warb::path!("emojos").and_then(get_emoji_list); enum RequestedSession { Session(Uuid, WatchSession),