From 671e7140d5f69c44bf6fe8b5e4b7dc139dec1666 Mon Sep 17 00:00:00 2001 From: morethanwords Date: Tue, 25 May 2021 14:00:47 +0300 Subject: [PATCH] Fix setting target on stickers helper Remove \uFE0F in emoji helper Fix emoji helper layout --- src/components/chat/input.ts | 8 +------- src/components/emoticonsDropdown/tabs/emoji.ts | 10 +--------- src/helpers/dom/attachListNavigation.ts | 1 + src/lib/richtextprocessor.ts | 17 ++++++++++++++++- src/scss/partials/_chatEmojiHelper.scss | 8 +++++++- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/components/chat/input.ts b/src/components/chat/input.ts index edca3af9..cf89c429 100644 --- a/src/components/chat/input.ts +++ b/src/components/chat/input.ts @@ -60,7 +60,6 @@ import { MarkdownType, markdownTags } from '../../helpers/dom/getRichElementValu import getRichValueWithCaret from '../../helpers/dom/getRichValueWithCaret'; import EmojiHelper from './emojiHelper'; import setRichFocus from '../../helpers/dom/setRichFocus'; -import { toCodePoints } from '../../vendor/emoji'; const RECORD_MIN_TIME = 500; const POSTING_MEDIA_NOT_ALLOWED = 'Posting media content isn\'t allowed in this group.'; @@ -1162,12 +1161,7 @@ export default class ChatInput { const hadEntities = RichTextProcessor.parseEntities(fullValue); RichTextProcessor.mergeEntities(entities, hadEntities); - const emojiEntity: MessageEntity.messageEntityEmoji = { - _: 'messageEntityEmoji', - offset: 0, - length: emoji.length, - unicode: toCodePoints(emoji).join('-') - }; + const emojiEntity = RichTextProcessor.getEmojiEntityFromEmoji(emoji); const addEntities: MessageEntity[] = [emojiEntity]; emojiEntity.offset = matchIndex; addEntities.push({ diff --git a/src/components/emoticonsDropdown/tabs/emoji.ts b/src/components/emoticonsDropdown/tabs/emoji.ts index 2ae332ab..39bc70e9 100644 --- a/src/components/emoticonsDropdown/tabs/emoji.ts +++ b/src/components/emoticonsDropdown/tabs/emoji.ts @@ -13,7 +13,6 @@ import Config from "../../../lib/config"; import { i18n, LangPackKey } from "../../../lib/langPack"; import { RichTextProcessor } from "../../../lib/richtextprocessor"; import rootScope from "../../../lib/rootScope"; -import { toCodePoints } from "../../../vendor/emoji"; import { putPreloader } from "../../misc"; import Scrollable from "../../scrollable"; import StickyIntersector from "../../stickyIntersector"; @@ -29,14 +28,7 @@ export function appendEmoji(emoji: string, container: HTMLElement, prepend = fal let kek: string; if(unify) { - kek = RichTextProcessor.wrapRichText(emoji, { - entities: [{ - _: 'messageEntityEmoji', - offset: 0, - length: emoji.length, - unicode: toCodePoints(emoji).join('-') - }] - }); + kek = RichTextProcessor.wrapSingleEmoji(emoji); } else { kek = RichTextProcessor.wrapEmojiText(emoji); } diff --git a/src/helpers/dom/attachListNavigation.ts b/src/helpers/dom/attachListNavigation.ts index b154c905..32148052 100644 --- a/src/helpers/dom/attachListNavigation.ts +++ b/src/helpers/dom/attachListNavigation.ts @@ -155,6 +155,7 @@ export default function attachListNavigation({list, type, onSelect, once, waitFo onKeyDown = _onKeyDown; document.addEventListener(HANDLE_EVENT, onKeyDown, {capture: true, passive: false}); + waitForKey = undefined; resetTarget(); } }; diff --git a/src/lib/richtextprocessor.ts b/src/lib/richtextprocessor.ts index efc50028..6b8afa9c 100644 --- a/src/lib/richtextprocessor.ts +++ b/src/lib/richtextprocessor.ts @@ -12,7 +12,7 @@ import Config from './config'; import emojiRegExp from '../vendor/emoji/regex'; -import { encodeEmoji } from '../vendor/emoji'; +import { encodeEmoji, toCodePoints } from '../vendor/emoji'; import { MessageEntity } from '../layer'; import { encodeEntities } from '../helpers/string'; import { isSafari } from '../helpers/userAgent'; @@ -840,6 +840,21 @@ namespace RichTextProcessor { export function isUsernameValid(username: string) { return ((username.length >= 5 && username.length <= 32) || !username.length) && /^[a-zA-Z0-9_]*$/.test(username); } + + export function getEmojiEntityFromEmoji(emoji: string): MessageEntity.messageEntityEmoji { + return { + _: 'messageEntityEmoji', + offset: 0, + length: emoji.length, + unicode: toCodePoints(emoji).join('-').replace(/-?fe0f/g, '') + }; + } + + export function wrapSingleEmoji(emoji: string) { + return wrapRichText(emoji, { + entities: [getEmojiEntityFromEmoji(emoji)] + }); + } } MOUNT_CLASS_TO.RichTextProcessor = RichTextProcessor; diff --git a/src/scss/partials/_chatEmojiHelper.scss b/src/scss/partials/_chatEmojiHelper.scss index 66ebcbbd..497a8b11 100644 --- a/src/scss/partials/_chatEmojiHelper.scss +++ b/src/scss/partials/_chatEmojiHelper.scss @@ -7,8 +7,14 @@ } .super-emojis { - display: block; + display: flex; white-space: nowrap; + align-items: center; + justify-content: flex-start; + } + + .super-emoji { + flex: 0 0 auto; } .super-emoji:not(.active) {