Update custom emoji entity format.
This commit is contained in:
parent
464c6a6171
commit
9cb7bb58f6
3 changed files with 16 additions and 7 deletions
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -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<QStringView>()
|
||||
: 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ using CustomEmojiFactory = Fn<std::unique_ptr<Text::CustomEmoji>(
|
|||
class PopupMenu;
|
||||
|
||||
void InsertEmojiAtCursor(QTextCursor cursor, EmojiPtr emoji);
|
||||
void InsertCustomEmojiAtCursor(
|
||||
QTextCursor cursor,
|
||||
const QString &text,
|
||||
const QString &link);
|
||||
|
||||
struct InstantReplaces {
|
||||
struct Node {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue