Fix emoji suggestions in monospace.

This commit is contained in:
John Preston 2019-01-21 11:02:20 +04:00
parent 805e4d01e7
commit 6066265717
2 changed files with 30 additions and 17 deletions

View File

@ -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<QString> checkOriginal) {
std::optional<QString> 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);

View File

@ -225,22 +225,11 @@ public:
void setInstantReplaces(const InstantReplaces &replaces);
void setInstantReplacesEnabled(rpl::producer<bool> enabled);
void setMarkdownReplacesEnabled(rpl::producer<bool> enabled);
void commitInstantReplacement(
int from,
int till,
const QString &with,
std::optional<QString> 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<QString> 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();