Update custom emoji entity format.

This commit is contained in:
John Preston 2022-07-05 23:35:03 +04:00
parent 464c6a6171
commit 9cb7bb58f6
3 changed files with 16 additions and 7 deletions

View file

@ -2213,7 +2213,7 @@ TextWithTags::Tags ConvertEntitiesToTextTags(
} break; } break;
case EntityType::CustomEmoji: { case EntityType::CustomEmoji: {
const auto match = QRegularExpression( const auto match = QRegularExpression(
"^(\\d+\\.\\d+:\\d+/\\d+)$" "^(\\d+:\\d+)$"
).match(entity.data()); ).match(entity.data());
if (match.hasMatch()) { if (match.hasMatch()) {
push(Ui::InputField::CustomEmojiLink(entity.data())); push(Ui::InputField::CustomEmojiLink(entity.data()));

View file

@ -130,13 +130,11 @@ bool IsNewline(QChar ch) {
[[nodiscard]] uint64 CustomEmojiIdFromLink(QStringView link) { [[nodiscard]] uint64 CustomEmojiIdFromLink(QStringView link) {
const auto skip = Ui::InputField::kCustomEmojiTagStart.size(); const auto skip = Ui::InputField::kCustomEmojiTagStart.size();
if (const auto i = link.indexOf('/', skip + 1); i > 0) { if (const auto i = link.indexOf(':', skip + 1); i > 0) {
const auto j = link.indexOf('?', i + 1);
return base::StringViewMid( return base::StringViewMid(
link, link,
i + 1, skip + 1,
(j > i) ? (j - i - 1) : -1 i - skip - 1).toULongLong();
).toULongLong();
} }
return 0; return 0;
} }
@ -1003,6 +1001,13 @@ void InsertCustomEmojiAtCursor(
format.setProperty(kCustomEmojiId, CustomEmojiIdFromLink(link)); format.setProperty(kCustomEmojiId, CustomEmojiIdFromLink(link));
format.setVerticalAlignment(QTextCharFormat::AlignBottom); format.setVerticalAlignment(QTextCharFormat::AlignBottom);
ApplyTagFormat(format, currentFormat); ApplyTagFormat(format, currentFormat);
auto existingTag = TagWithoutCustomEmoji(
format.property(kTagProperty).toString());
auto existingTags = existingTag.isEmpty()
? QList<QStringView>()
: TextUtilities::SplitTags(existingTag);
existingTags.push_back(link);
format.setProperty(kTagProperty, TextUtilities::JoinTag(existingTags));
cursor.insertText(kObjectReplacement, format); cursor.insertText(kObjectReplacement, format);
} }
@ -3581,7 +3586,7 @@ QString InputField::CustomEmojiLink(QStringView entityData) {
QString InputField::CustomEmojiEntityData(QStringView link) { QString InputField::CustomEmojiEntityData(QStringView link) {
const auto match = qthelp::regex_match( const auto match = qthelp::regex_match(
"^(\\d+\\.\\d+:\\d+/\\d+)(\\?|$)", "^(\\d+:\\d+)(\\?|$)",
base::StringViewMid(link, kCustomEmojiTagStart.size())); base::StringViewMid(link, kCustomEmojiTagStart.size()));
return match ? match->captured(1) : QString(); return match ? match->captured(1) : QString();
} }

View file

@ -42,6 +42,10 @@ using CustomEmojiFactory = Fn<std::unique_ptr<Text::CustomEmoji>(
class PopupMenu; class PopupMenu;
void InsertEmojiAtCursor(QTextCursor cursor, EmojiPtr emoji); void InsertEmojiAtCursor(QTextCursor cursor, EmojiPtr emoji);
void InsertCustomEmojiAtCursor(
QTextCursor cursor,
const QString &text,
const QString &link);
struct InstantReplaces { struct InstantReplaces {
struct Node { struct Node {