Custom instant replaces
This commit is contained in:
parent
3b2cbce204
commit
f69cde56f1
2 changed files with 15 additions and 0 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QtGui/QTextDocumentFragment>
|
#include <QtGui/QTextDocumentFragment>
|
||||||
#include <QtCore/QMimeData>
|
#include <QtCore/QMimeData>
|
||||||
#include <QtCore/QRegularExpression>
|
#include <QtCore/QRegularExpression>
|
||||||
|
#include <QtCore/QMap>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
@ -48,6 +49,8 @@ const auto kNewlineChars = QString("\r\n")
|
||||||
+ QChar(QChar::ParagraphSeparator)
|
+ QChar(QChar::ParagraphSeparator)
|
||||||
+ QChar(QChar::LineSeparator);
|
+ QChar(QChar::LineSeparator);
|
||||||
|
|
||||||
|
QMap<QString, QString> customReplacesMap;
|
||||||
|
|
||||||
class InputDocument : public QTextDocument {
|
class InputDocument : public QTextDocument {
|
||||||
public:
|
public:
|
||||||
InputDocument(QObject *parent, const style::InputField &st);
|
InputDocument(QObject *parent, const style::InputField &st);
|
||||||
|
|
@ -809,6 +812,10 @@ struct FormattingAction {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void AddCustomReplacement(QString from, QString to) {
|
||||||
|
customReplacesMap.insert(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
// kTagUnderline is not used for Markdown.
|
// kTagUnderline is not used for Markdown.
|
||||||
|
|
||||||
const QString InputField::kTagBold = QStringLiteral("**");
|
const QString InputField::kTagBold = QStringLiteral("**");
|
||||||
|
|
@ -903,6 +910,9 @@ const InstantReplaces &InstantReplaces::Default() {
|
||||||
Assert(emoji != nullptr);
|
Assert(emoji != nullptr);
|
||||||
result.add(what, emoji->text());
|
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;
|
||||||
}();
|
}();
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -917,6 +927,9 @@ const InstantReplaces &InstantReplaces::TextOnly() {
|
||||||
result.add(
|
result.add(
|
||||||
":shrug:",
|
":shrug:",
|
||||||
QChar(175) + QString("\\_(") + QChar(12484) + ")_/" + QChar(175));
|
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;
|
||||||
}();
|
}();
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ class Painter;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
|
void AddCustomReplacement(QString from, QString to);
|
||||||
|
|
||||||
const auto kClearFormatSequence = QKeySequence("ctrl+shift+n");
|
const auto kClearFormatSequence = QKeySequence("ctrl+shift+n");
|
||||||
const auto kStrikeOutSequence = QKeySequence("ctrl+shift+x");
|
const auto kStrikeOutSequence = QKeySequence("ctrl+shift+x");
|
||||||
const auto kMonospaceSequence = QKeySequence("ctrl+shift+m");
|
const auto kMonospaceSequence = QKeySequence("ctrl+shift+m");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue