From 6066265717dd39d3905ceb1cef052f5f40c4f26f Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 21 Jan 2019 11:02:20 +0400 Subject: [PATCH] Fix emoji suggestions in monospace. --- .../SourceFiles/ui/widgets/input_fields.cpp | 20 ++++++++++---- .../SourceFiles/ui/widgets/input_fields.h | 27 ++++++++++--------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index fc9c312194..d3b47e0f6c 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -2895,14 +2895,22 @@ void InputField::applyInstantReplace( } else if (position < length) { return; } - commitInstantReplacement(position - length, position, with, what); + commitInstantReplacement(position - length, position, with, what, true); +} + +void InputField::commitInstantReplacement( + int from, + int till, + const QString &with) { + commitInstantReplacement(from, till, with, std::nullopt, false); } void InputField::commitInstantReplacement( int from, int till, const QString &with, - std::optional checkOriginal) { + std::optional checkOriginal, + bool checkIfInMonospace) { const auto original = getTextWithTagsPart(from, till).text; if (checkOriginal && checkOriginal->compare(original, Qt::CaseInsensitive) != 0) { @@ -2910,9 +2918,11 @@ void InputField::commitInstantReplacement( } auto cursor = textCursor(); - const auto currentTag = cursor.charFormat().property(kTagProperty); - if (currentTag == kTagPre || currentTag == kTagCode) { - return; + if (checkIfInMonospace) { + const auto currentTag = cursor.charFormat().property(kTagProperty); + if (currentTag == kTagPre || currentTag == kTagCode) { + return; + } } cursor.setPosition(from); cursor.setPosition(till, QTextCursor::KeepAnchor); diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index 9579896863..d2cedebf59 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -225,22 +225,11 @@ public: void setInstantReplaces(const InstantReplaces &replaces); void setInstantReplacesEnabled(rpl::producer enabled); void setMarkdownReplacesEnabled(rpl::producer enabled); - void commitInstantReplacement( - int from, - int till, - const QString &with, - std::optional checkOriginal = std::nullopt); - bool commitMarkdownReplacement( - int from, - int till, - const QString &tag, - const QString &edge = QString()); + void commitInstantReplacement(int from, int till, const QString &with); void commitMarkdownLinkEdit( EditLinkSelection selection, const QString &text, const QString &link); - void toggleSelectionMarkdown(const QString &tag); - void clearSelectionMarkdown(); static bool IsValidMarkdownLink(const QString &link); const QString &getLastText() const { @@ -408,6 +397,20 @@ private: EditLinkSelection editLinkSelection(QContextMenuEvent *e) const; void editMarkdownLink(EditLinkSelection selection); + void commitInstantReplacement( + int from, + int till, + const QString &with, + std::optional checkOriginal, + bool checkIfInMonospace); + bool commitMarkdownReplacement( + int from, + int till, + const QString &tag, + const QString &edge = QString()); + void toggleSelectionMarkdown(const QString &tag); + void clearSelectionMarkdown(); + bool revertFormatReplace(); void highlightMarkdown();