diff --git a/ui/widgets/input_fields.cpp b/ui/widgets/input_fields.cpp index db17e0c..ded3b52 100644 --- a/ui/widgets/input_fields.cpp +++ b/ui/widgets/input_fields.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace Ui { namespace { @@ -48,6 +49,8 @@ const auto kNewlineChars = QString("\r\n") + QChar(QChar::ParagraphSeparator) + QChar(QChar::LineSeparator); +QMap customReplacesMap; + class InputDocument : public QTextDocument { public: InputDocument(QObject *parent, const style::InputField &st); @@ -809,6 +812,10 @@ struct FormattingAction { } // namespace +void AddCustomReplacement(QString from, QString to) { + customReplacesMap.insert(from, to); +} + // kTagUnderline is not used for Markdown. const QString InputField::kTagBold = QStringLiteral("**"); @@ -903,6 +910,9 @@ const InstantReplaces &InstantReplaces::Default() { Assert(emoji != nullptr); result.add(what, emoji->text()); } + for (auto i = customReplacesMap.constBegin(), e = customReplacesMap.constEnd(); i != e; ++i) { + result.add(i.key(), i.value()); + } return result; }(); return result; @@ -917,6 +927,9 @@ const InstantReplaces &InstantReplaces::TextOnly() { result.add( ":shrug:", QChar(175) + QString("\\_(") + QChar(12484) + ")_/" + QChar(175)); + for (auto i = customReplacesMap.constBegin(), e = customReplacesMap.constEnd(); i != e; ++i) { + result.add(i.key(), i.value()); + } return result; }(); return result; diff --git a/ui/widgets/input_fields.h b/ui/widgets/input_fields.h index 2873ea7..3e2fbd3 100644 --- a/ui/widgets/input_fields.h +++ b/ui/widgets/input_fields.h @@ -22,6 +22,8 @@ class Painter; namespace Ui { +void AddCustomReplacement(QString from, QString to); + const auto kClearFormatSequence = QKeySequence("ctrl+shift+n"); const auto kStrikeOutSequence = QKeySequence("ctrl+shift+x"); const auto kMonospaceSequence = QKeySequence("ctrl+shift+m");