diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 3809c0d735..7184fb3104 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -427,14 +427,17 @@ not_null EditAdminBox::addRankInput() { this, st::customBadgeField, (isOwner ? tr::lng_owner_badge : tr::lng_admin_badge)(), - _oldRank), + TextUtilities::RemoveEmoji(_oldRank)), st::rightsAboutMargin); result->setMaxLength(kAdminRoleLimit); - result->setInstantReplaces(Ui::InstantReplaces::Default()); - result->setInstantReplacesEnabled(Global::ReplaceEmojiValue()); - Ui::Emoji::SuggestionsController::Init( - getDelegate()->outerContainer(), - result); + result->setInstantReplaces(Ui::InstantReplaces::TextOnly()); + connect(result, &Ui::InputField::changed, [=] { + const auto text = result->getLastText(); + const auto removed = TextUtilities::RemoveEmoji(text); + if (removed != text) { + result->setText(removed); + } + }); addControl( object_ptr( diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index dcee0afc6f..8be10b8cf9 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -674,7 +674,7 @@ void HistoryMessage::refreshMessageBadge() { } else { _messageBadge.setText( st::defaultTextStyle, - TextUtilities::SingleLine(text)); + TextUtilities::RemoveEmoji(TextUtilities::SingleLine(text))); } } diff --git a/Telegram/SourceFiles/ui/text/text_entity.cpp b/Telegram/SourceFiles/ui/text/text_entity.cpp index 2cb1b3c76b..7100889b24 100644 --- a/Telegram/SourceFiles/ui/text/text_entity.cpp +++ b/Telegram/SourceFiles/ui/text/text_entity.cpp @@ -1302,6 +1302,23 @@ QString RemoveAccents(const QString &text) { return (i < result.size()) ? result.mid(0, i) : result; } +QString RemoveEmoji(const QString &text) { + auto result = QString(); + result.reserve(text.size()); + + auto begin = text.data(); + const auto end = begin + text.size(); + while (begin != end) { + auto length = 0; + if (Ui::Emoji::Find(begin, end, &length)) { + begin += length; + } else { + result.append(*begin++); + } + } + return result; +} + QStringList PrepareSearchWords(const QString &query, const QRegularExpression *SplitterOverride) { auto clean = RemoveAccents(query.trimmed().toLower()); auto result = QStringList(); diff --git a/Telegram/SourceFiles/ui/text/text_entity.h b/Telegram/SourceFiles/ui/text/text_entity.h index d227204a43..56ebcb9c01 100644 --- a/Telegram/SourceFiles/ui/text/text_entity.h +++ b/Telegram/SourceFiles/ui/text/text_entity.h @@ -281,6 +281,7 @@ QString Clean(const QString &text); QString EscapeForRichParsing(const QString &text); QString SingleLine(const QString &text); QString RemoveAccents(const QString &text); +QString RemoveEmoji(const QString &text); QStringList PrepareSearchWords(const QString &query, const QRegularExpression *SplitterOverride = nullptr); bool CutPart(TextWithEntities &sending, TextWithEntities &left, int limit); diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index 5fc342e3c5..9b12b33f8e 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -936,6 +936,20 @@ const InstantReplaces &InstantReplaces::Default() { return result; } +const InstantReplaces &InstantReplaces::TextOnly() { + static const auto result = [] { + auto result = InstantReplaces(); + result.add("--", QString(1, QChar(8212))); + result.add("<<", QString(1, QChar(171))); + result.add(">>", QString(1, QChar(187))); + result.add( + ":shrug:", + QChar(175) + QString("\\_(") + QChar(12484) + ")_/" + QChar(175)); + return result; + }(); + return result; +} + FlatInput::FlatInput( QWidget *parent, const style::FlatInput &st, diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index 850d7fd4e6..9d33a2c5d3 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -28,6 +28,7 @@ struct InstantReplaces { void add(const QString &what, const QString &with); static const InstantReplaces &Default(); + static const InstantReplaces &TextOnly(); int maxLength = 0; Node reverseMap;