[Option][JSON] Custom auto-replaces
This commit is contained in:
parent
f72187a321
commit
169ac07519
2 changed files with 36 additions and 0 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include <QtWidgets/QCommonStyle>
|
||||
#include <QtWidgets/QScrollBar>
|
||||
#include <QtWidgets/QTextEdit>
|
||||
#include <QtCore/QMap>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
|
|
@ -73,6 +74,8 @@ const auto kNewlineChars = QString("\r\n")
|
|||
+ QChar(QChar::ParagraphSeparator)
|
||||
+ QChar(QChar::LineSeparator);
|
||||
|
||||
QMap<QString, QString> customReplacesMap;
|
||||
|
||||
// We need unique tags otherwise same custom emoji would join in a single
|
||||
// QTextCharFormat with the same properties, including kCustomEmojiText.
|
||||
auto GlobalCustomEmojiCounter = 0;
|
||||
|
|
@ -936,6 +939,10 @@ struct FormattingAction {
|
|||
|
||||
} // namespace
|
||||
|
||||
void AddCustomReplacement(QString from, QString to) {
|
||||
customReplacesMap.insert(from, to);
|
||||
}
|
||||
|
||||
// kTagUnderline is not used for Markdown.
|
||||
|
||||
const QString InputField::kTagBold = u"**"_q;
|
||||
|
|
@ -1079,6 +1086,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;
|
||||
|
|
@ -1093,6 +1103,20 @@ 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;
|
||||
}
|
||||
|
||||
const InstantReplaces &InstantReplaces::Custom() {
|
||||
static const auto result = [] {
|
||||
auto result = InstantReplaces();
|
||||
for (auto i = customReplacesMap.constBegin(), e = customReplacesMap.constEnd(); i != e; ++i) {
|
||||
result.add(i.key(), i.value());
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
return result;
|
||||
|
|
@ -1414,6 +1438,14 @@ void InputField::setInstantReplaces(const InstantReplaces &replaces) {
|
|||
_mutableInstantReplaces = replaces;
|
||||
}
|
||||
|
||||
void InputField::setInstantReplaces(rpl::producer<InstantReplaces> producer) {
|
||||
std::move(
|
||||
producer
|
||||
) | rpl::start_with_next([=](InstantReplaces replaces) {
|
||||
_mutableInstantReplaces = replaces;
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void InputField::setInstantReplacesEnabled(rpl::producer<bool> enabled) {
|
||||
std::move(
|
||||
enabled
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ struct InputField;
|
|||
|
||||
namespace Ui {
|
||||
|
||||
void AddCustomReplacement(QString from, QString to);
|
||||
|
||||
const auto kClearFormatSequence = QKeySequence("ctrl+shift+n");
|
||||
const auto kStrikeOutSequence = QKeySequence("ctrl+shift+x");
|
||||
const auto kBlockquoteSequence = QKeySequence("ctrl+shift+.");
|
||||
|
|
@ -60,6 +62,7 @@ struct InstantReplaces {
|
|||
|
||||
static const InstantReplaces &Default();
|
||||
static const InstantReplaces &TextOnly();
|
||||
static const InstantReplaces &Custom();
|
||||
|
||||
int maxLength = 0;
|
||||
Node reverseMap;
|
||||
|
|
@ -221,6 +224,7 @@ public:
|
|||
void setAdditionalMargins(QMargins margins);
|
||||
|
||||
void setInstantReplaces(const InstantReplaces &replaces);
|
||||
void setInstantReplaces(rpl::producer<InstantReplaces> producer);
|
||||
void setInstantReplacesEnabled(rpl::producer<bool> enabled);
|
||||
void setMarkdownReplacesEnabled(rpl::producer<bool> enabled);
|
||||
void setExtendedContextMenu(rpl::producer<ExtendedContextMenu> value);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue