[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/QCommonStyle>
|
||||||
#include <QtWidgets/QScrollBar>
|
#include <QtWidgets/QScrollBar>
|
||||||
#include <QtWidgets/QTextEdit>
|
#include <QtWidgets/QTextEdit>
|
||||||
|
#include <QtCore/QMap>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
@ -73,6 +74,8 @@ const auto kNewlineChars = QString("\r\n")
|
||||||
+ QChar(QChar::ParagraphSeparator)
|
+ QChar(QChar::ParagraphSeparator)
|
||||||
+ QChar(QChar::LineSeparator);
|
+ QChar(QChar::LineSeparator);
|
||||||
|
|
||||||
|
QMap<QString, QString> customReplacesMap;
|
||||||
|
|
||||||
// We need unique tags otherwise same custom emoji would join in a single
|
// We need unique tags otherwise same custom emoji would join in a single
|
||||||
// QTextCharFormat with the same properties, including kCustomEmojiText.
|
// QTextCharFormat with the same properties, including kCustomEmojiText.
|
||||||
auto GlobalCustomEmojiCounter = 0;
|
auto GlobalCustomEmojiCounter = 0;
|
||||||
|
|
@ -936,6 +939,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 = u"**"_q;
|
const QString InputField::kTagBold = u"**"_q;
|
||||||
|
|
@ -1079,6 +1086,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;
|
||||||
|
|
@ -1093,6 +1103,20 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}();
|
}();
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1414,6 +1438,14 @@ void InputField::setInstantReplaces(const InstantReplaces &replaces) {
|
||||||
_mutableInstantReplaces = 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) {
|
void InputField::setInstantReplacesEnabled(rpl::producer<bool> enabled) {
|
||||||
std::move(
|
std::move(
|
||||||
enabled
|
enabled
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ struct InputField;
|
||||||
|
|
||||||
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 kBlockquoteSequence = QKeySequence("ctrl+shift+.");
|
const auto kBlockquoteSequence = QKeySequence("ctrl+shift+.");
|
||||||
|
|
@ -60,6 +62,7 @@ struct InstantReplaces {
|
||||||
|
|
||||||
static const InstantReplaces &Default();
|
static const InstantReplaces &Default();
|
||||||
static const InstantReplaces &TextOnly();
|
static const InstantReplaces &TextOnly();
|
||||||
|
static const InstantReplaces &Custom();
|
||||||
|
|
||||||
int maxLength = 0;
|
int maxLength = 0;
|
||||||
Node reverseMap;
|
Node reverseMap;
|
||||||
|
|
@ -221,6 +224,7 @@ public:
|
||||||
void setAdditionalMargins(QMargins margins);
|
void setAdditionalMargins(QMargins margins);
|
||||||
|
|
||||||
void setInstantReplaces(const InstantReplaces &replaces);
|
void setInstantReplaces(const InstantReplaces &replaces);
|
||||||
|
void setInstantReplaces(rpl::producer<InstantReplaces> producer);
|
||||||
void setInstantReplacesEnabled(rpl::producer<bool> enabled);
|
void setInstantReplacesEnabled(rpl::producer<bool> enabled);
|
||||||
void setMarkdownReplacesEnabled(rpl::producer<bool> enabled);
|
void setMarkdownReplacesEnabled(rpl::producer<bool> enabled);
|
||||||
void setExtendedContextMenu(rpl::producer<ExtendedContextMenu> value);
|
void setExtendedContextMenu(rpl::producer<ExtendedContextMenu> value);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue