diff --git a/ui/text/text_entity.cpp b/ui/text/text_entity.cpp index d5fd44a..0dc3676 100644 --- a/ui/text/text_entity.cpp +++ b/ui/text/text_entity.cpp @@ -2213,7 +2213,7 @@ TextWithTags::Tags ConvertEntitiesToTextTags( } break; case EntityType::CustomEmoji: { const auto match = QRegularExpression( - "^(\\d+\\.\\d+:\\d+/\\d+)$" + "^(\\d+:\\d+)$" ).match(entity.data()); if (match.hasMatch()) { push(Ui::InputField::CustomEmojiLink(entity.data())); diff --git a/ui/widgets/input_fields.cpp b/ui/widgets/input_fields.cpp index 18fac3e..75e2e34 100644 --- a/ui/widgets/input_fields.cpp +++ b/ui/widgets/input_fields.cpp @@ -130,13 +130,11 @@ bool IsNewline(QChar ch) { [[nodiscard]] uint64 CustomEmojiIdFromLink(QStringView link) { const auto skip = Ui::InputField::kCustomEmojiTagStart.size(); - if (const auto i = link.indexOf('/', skip + 1); i > 0) { - const auto j = link.indexOf('?', i + 1); + if (const auto i = link.indexOf(':', skip + 1); i > 0) { return base::StringViewMid( link, - i + 1, - (j > i) ? (j - i - 1) : -1 - ).toULongLong(); + skip + 1, + i - skip - 1).toULongLong(); } return 0; } @@ -1003,6 +1001,13 @@ void InsertCustomEmojiAtCursor( format.setProperty(kCustomEmojiId, CustomEmojiIdFromLink(link)); format.setVerticalAlignment(QTextCharFormat::AlignBottom); ApplyTagFormat(format, currentFormat); + auto existingTag = TagWithoutCustomEmoji( + format.property(kTagProperty).toString()); + auto existingTags = existingTag.isEmpty() + ? QList() + : TextUtilities::SplitTags(existingTag); + existingTags.push_back(link); + format.setProperty(kTagProperty, TextUtilities::JoinTag(existingTags)); cursor.insertText(kObjectReplacement, format); } @@ -3581,7 +3586,7 @@ QString InputField::CustomEmojiLink(QStringView entityData) { QString InputField::CustomEmojiEntityData(QStringView link) { const auto match = qthelp::regex_match( - "^(\\d+\\.\\d+:\\d+/\\d+)(\\?|$)", + "^(\\d+:\\d+)(\\?|$)", base::StringViewMid(link, kCustomEmojiTagStart.size())); return match ? match->captured(1) : QString(); } diff --git a/ui/widgets/input_fields.h b/ui/widgets/input_fields.h index e2d7bd7..67fffed 100644 --- a/ui/widgets/input_fields.h +++ b/ui/widgets/input_fields.h @@ -42,6 +42,10 @@ using CustomEmojiFactory = Fn( class PopupMenu; void InsertEmojiAtCursor(QTextCursor cursor, EmojiPtr emoji); +void InsertCustomEmojiAtCursor( + QTextCursor cursor, + const QString &text, + const QString &link); struct InstantReplaces { struct Node {