Forum: typing notices, smileys to emoji while typing, no emoji tray
"Holdfény gépel…" shows in threads and private conversations: the page says over the live connection (every few seconds while typing) that its member types, and the forum service passes it to those who may see that place, never back to the typer. The emoji tray is gone (phones have their emoji keyboard); character smileys turn into emoji as they are typed, from a longer list shared with the server (which also converts titles now; <3 is a red heart). Emoji show in colour: the forum's font stack names the systems' colour emoji fonts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// The old forums' character smileys, turned into emoji while typing (the
|
||||
// forum service converts the same list on save: services/forum/src/text.rs).
|
||||
// A smiley converts only standing alone, once a space or line break follows
|
||||
// it, so links and the like stay as typed.
|
||||
|
||||
export const EMOTICONS: [string, string][] = [
|
||||
[":)", "🙂"],
|
||||
[":-)", "🙂"],
|
||||
["(:", "🙂"],
|
||||
[":D", "😄"],
|
||||
[":-D", "😄"],
|
||||
["xD", "😆"],
|
||||
["XD", "😆"],
|
||||
[";)", "😉"],
|
||||
[";-)", "😉"],
|
||||
[":(", "🙁"],
|
||||
[":-(", "🙁"],
|
||||
[":'(", "😢"],
|
||||
[":P", "😛"],
|
||||
[":-P", "😛"],
|
||||
[":p", "😛"],
|
||||
[":O", "😮"],
|
||||
[":o", "😮"],
|
||||
[":-O", "😮"],
|
||||
[":*", "😘"],
|
||||
[":-*", "😘"],
|
||||
[":/", "😕"],
|
||||
[":|", "😐"],
|
||||
["B)", "😎"],
|
||||
["^^", "😊"],
|
||||
["^_^", "😊"],
|
||||
["<3", "❤️"],
|
||||
["</3", "💔"],
|
||||
];
|
||||
|
||||
const LOOKUP = new Map(EMOTICONS);
|
||||
const ALTERNATIVES = [...LOOKUP.keys()]
|
||||
.sort((a, b) => b.length - a.length)
|
||||
.map((code) => code.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
||||
.join("|");
|
||||
|
||||
/**
|
||||
* The text with its finished smileys as emoji, and where the caret goes.
|
||||
* `atEnd`: also a smiley at the very end (when sending).
|
||||
*/
|
||||
export function convertEmoticons(text: string, caret: number, atEnd = false): { text: string; caret: number } {
|
||||
const pattern = new RegExp(`(^|\\s)(${ALTERNATIVES})(?=\\s${atEnd ? "|$" : ""})`, "g");
|
||||
let shift = 0;
|
||||
const converted = text.replace(pattern, (match, space: string, code: string, offset: number) => {
|
||||
const emoji = LOOKUP.get(code) ?? code;
|
||||
if (offset + space.length < caret) shift += emoji.length - code.length;
|
||||
return space + emoji;
|
||||
});
|
||||
return { text: converted, caret: caret + shift };
|
||||
}
|
||||
|
||||
/**
|
||||
* For a text field's change: converts and puts the caret back where it was
|
||||
* (a controlled field would jump it to the end).
|
||||
*/
|
||||
export function withEmoji(e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>, set: (text: string) => void) {
|
||||
const el = e.target;
|
||||
const { text, caret } = convertEmoticons(el.value, el.selectionStart ?? el.value.length);
|
||||
set(text);
|
||||
if (text !== el.value) {
|
||||
requestAnimationFrame(() => el.setSelectionRange(caret, caret));
|
||||
}
|
||||
}
|
||||
@@ -198,38 +198,6 @@ export const INTENTS = {
|
||||
advice: { label: "Tanácsot, véleményt kér", short: "Tanácsot kér" },
|
||||
} as const;
|
||||
|
||||
/** The emoji offered first in the composer: the Moon, the signs, warmth. */
|
||||
export const EMOJI = [
|
||||
"🙂",
|
||||
"😊",
|
||||
"🤍",
|
||||
"🙏",
|
||||
"✨",
|
||||
"🌙",
|
||||
"🌕",
|
||||
"🌑",
|
||||
"⭐",
|
||||
"🌸",
|
||||
"🍀",
|
||||
"🕯️",
|
||||
"🌿",
|
||||
"☕",
|
||||
"😢",
|
||||
"🤗",
|
||||
"♈",
|
||||
"♉",
|
||||
"♊",
|
||||
"♋",
|
||||
"♌",
|
||||
"♍",
|
||||
"♎",
|
||||
"♏",
|
||||
"♐",
|
||||
"♑",
|
||||
"♒",
|
||||
"♓",
|
||||
];
|
||||
|
||||
/** `/forum/szal/123-nem-tudom-elengedni`: the number decides, the words are for reading. */
|
||||
export function threadHref(t: { id: number; slug: string }, postId?: number): string {
|
||||
const path = t.slug ? `/forum/szal/${t.id}-${t.slug}` : `/forum/szal/${t.id}`;
|
||||
|
||||
Reference in New Issue
Block a user