From 14a7fc74af32af350d65edc253d1763a9574c289 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 24 Jun 2022 10:48:46 +0400 Subject: [PATCH] Correctly finish custom emoji entities. --- ui/text/text.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ui/text/text.cpp b/ui/text/text.cpp index 2073ea8..bcefacd 100644 --- a/ui/text/text.cpp +++ b/ui/text/text.cpp @@ -215,14 +215,16 @@ private: Link, IndexedLink, Spoiler, + CustomEmoji, }; explicit StartedEntity(TextBlockFlags flags); explicit StartedEntity(uint16 index, Type type); - std::optional flags() const; - std::optional lnkIndex() const; - std::optional spoilerIndex() const; + [[nodiscard]] Type type() const; + [[nodiscard]] std::optional flags() const; + [[nodiscard]] std::optional lnkIndex() const; + [[nodiscard]] std::optional spoilerIndex() const; private: const int _value = 0; @@ -323,6 +325,10 @@ Parser::StartedEntity::StartedEntity(uint16 index, Type type) : (_value < kStringLinkIndexShift)); } +Parser::StartedEntity::Type Parser::StartedEntity::type() const { + return _type; +} + std::optional Parser::StartedEntity::flags() const { if (_value < int(kStringLinkIndexShift) && (_type == Type::Flags)) { return TextBlockFlags(_value); @@ -450,7 +456,9 @@ void Parser::finishEntities() { _startedEntities.erase(_startedEntities.begin()); while (!list.empty()) { - if (const auto flags = list.back().flags()) { + if (list.back().type() == StartedEntity::Type::CustomEmoji) { + createBlock(); + } else if (const auto flags = list.back().flags()) { if (_flags & (*flags)) { createBlock(); _flags &= ~(*flags); @@ -509,9 +517,13 @@ bool Parser::checkEntities() { link.data = _waitingEntity->data(); link.text = QString(entityBegin, entityLength); }; + + using Type = StartedEntity::Type; + if (entityType == EntityType::CustomEmoji) { createBlock(); _customEmojiData = _waitingEntity->data(); + _startedEntities[entityEnd].emplace_back(0, Type::CustomEmoji); } else if (entityType == EntityType::Bold) { flags = TextBlockFBold; } else if (entityType == EntityType::Semibold) { @@ -568,8 +580,6 @@ bool Parser::checkEntities() { pushComplexUrl(); } - using Type = StartedEntity::Type; - if (link.type != EntityType::Invalid) { createBlock();