Skip to content

Commit

Permalink
Fix colored custom emoji in field.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Dec 15, 2022
1 parent 770b5d0 commit 4befce5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ui/widgets/input_fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,12 @@ void ApplyTagFormat(QTextCharFormat &to, const QTextCharFormat &from) {
}
to.setProperty(kReplaceTagId, from.property(kReplaceTagId));
to.setFont(from.font());
to.setForeground(from.foreground());
to.setBackground(from.background());
if (from.hasProperty(QTextFormat::ForegroundBrush)) {
to.setForeground(from.brushProperty(QTextFormat::ForegroundBrush));
}
if (from.hasProperty(QTextFormat::BackgroundBrush)) {
to.setBackground(from.brushProperty(QTextFormat::BackgroundBrush));
}
}

// Returns the position of the first inserted tag or "changedEnd" value if none found.
Expand Down Expand Up @@ -1012,6 +1016,7 @@ void InsertEmojiAtCursor(QTextCursor cursor, EmojiPtr emoji) {
}

void InsertCustomEmojiAtCursor(
not_null<InputField*> field,
QTextCursor cursor,
const QString &text,
const QString &link) {
Expand All @@ -1023,6 +1028,9 @@ void InsertCustomEmojiAtCursor(
format.setProperty(kCustomEmojiLink, unique);
format.setProperty(kCustomEmojiId, CustomEmojiIdFromLink(link));
format.setVerticalAlignment(QTextCharFormat::AlignBottom);
format.setFont(field->st().font);
format.setForeground(field->st().textFg);
format.setBackground(QBrush());
ApplyTagFormat(format, currentFormat);
format.setProperty(kTagProperty, TextUtilities::TagWithAdded(
format.property(kTagProperty).toString(),
Expand Down Expand Up @@ -2239,6 +2247,7 @@ void InputField::processFormatting(int insertPosition, int insertEnd) {
InsertEmojiAtCursor(cursor, action.emoji);
} else {
InsertCustomEmojiAtCursor(
this,
cursor,
action.customEmojiText,
action.customEmojiLink);
Expand Down
6 changes: 6 additions & 0 deletions ui/widgets/input_fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ const auto kEditLinkSequence = QKeySequence("ctrl+k");
const auto kSpoilerSequence = QKeySequence("ctrl+shift+p");

class PopupMenu;
class InputField;

void InsertEmojiAtCursor(QTextCursor cursor, EmojiPtr emoji);
void InsertCustomEmojiAtCursor(
not_null<InputField*> field,
QTextCursor cursor,
const QString &text,
const QString &link);
Expand Down Expand Up @@ -152,6 +154,10 @@ class InputField : public RpWidget {
rpl::producer<QString> placeholder = nullptr,
const TextWithTags &value = TextWithTags());

[[nodiscard]] const style::InputField &st() const {
return _st;
}

void showError();
void showErrorNoFocus();
void hideError();
Expand Down

0 comments on commit 4befce5

Please sign in to comment.