From bd3c5fc3725229e9517fbdba93fa25b0949416ee Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Thu, 26 Aug 2021 15:54:41 +0300 Subject: [PATCH] Fix splitted emoji --- src/index.ts | 1 - src/lib/richtextprocessor.ts | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4f7c0c0b..70b48caf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,6 @@ import App from './config/app'; import blurActiveElement from './helpers/dom/blurActiveElement'; import { cancelEvent } from './helpers/dom/cancelEvent'; -import fixSafariStickyInput from './helpers/dom/fixSafariStickyInput'; import { IS_STICKY_INPUT_BUGGED } from './helpers/dom/fixSafariStickyInputFocusing'; import loadFonts from './helpers/dom/loadFonts'; import IS_EMOJI_SUPPORTED from './helpers/emojiSupport'; diff --git a/src/lib/richtextprocessor.ts b/src/lib/richtextprocessor.ts index 1d3aac93..6dd0d842 100644 --- a/src/lib/richtextprocessor.ts +++ b/src/lib/richtextprocessor.ts @@ -382,6 +382,19 @@ namespace RichTextProcessor { currentEntities.push(...filtered); currentEntities.sort((a, b) => a.offset - b.offset); + + if(!emojiSupported) { // fix splitted emoji. messageEntityTextUrl can split the emoji if starts before its end (e.g. on fe0f) + for(let i = 0; i < currentEntities.length; ++i) { + const entity = currentEntities[i]; + if(entity._ === 'messageEntityEmoji') { + const nextEntity = currentEntities[i + 1]; + if(nextEntity && nextEntity.offset < (entity.offset + entity.length)) { + entity.length = nextEntity.offset - entity.offset; + } + } + } + } + return currentEntities; }