Allow better InputField content restriction.
This commit is contained in:
parent
fee301f941
commit
e3eabf8eff
2 changed files with 25 additions and 12 deletions
|
|
@ -51,7 +51,6 @@ constexpr auto kReplaceTagId = QTextFormat::UserProperty + 3;
|
|||
constexpr auto kTagProperty = QTextFormat::UserProperty + 4;
|
||||
constexpr auto kCustomEmojiText = QTextFormat::UserProperty + 5;
|
||||
constexpr auto kCustomEmojiLink = QTextFormat::UserProperty + 6;
|
||||
constexpr auto kCustomEmojiId = QTextFormat::UserProperty + 7;
|
||||
const auto kObjectReplacementCh = QChar(QChar::ObjectReplacementCharacter);
|
||||
const auto kObjectReplacement = QString::fromRawData(
|
||||
&kObjectReplacementCh,
|
||||
|
|
@ -65,6 +64,7 @@ const auto &kTagPre = InputField::kTagPre;
|
|||
const auto &kTagBlockquote = InputField::kTagBlockquote;
|
||||
const auto &kTagSpoiler = InputField::kTagSpoiler;
|
||||
const auto &kCustomEmojiFormat = InputField::kCustomEmojiFormat;
|
||||
const auto &kCustomEmojiId = InputField::kCustomEmojiId;
|
||||
const auto kTagCheckLinkMeta = u"^:/:/:^"_q;
|
||||
const auto kNewlineChars = QString("\r\n")
|
||||
+ QChar(0xfdd0) // QTextBeginningOfFrame
|
||||
|
|
@ -711,14 +711,6 @@ QTextImageFormat PrepareEmojiFormat(EmojiPtr emoji, const QFont &font) {
|
|||
return result;
|
||||
}
|
||||
|
||||
// Optimization: with null page size document does not re-layout
|
||||
// on each insertText / mergeCharFormat.
|
||||
void PrepareFormattingOptimization(not_null<QTextDocument*> document) {
|
||||
if (!document->pageSize().isNull()) {
|
||||
document->setPageSize(QSizeF(0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveDocumentTags(
|
||||
const style::InputField &st,
|
||||
not_null<QTextDocument*> document,
|
||||
|
|
@ -954,8 +946,8 @@ const QString InputField::kTagPre = u"```"_q;
|
|||
const QString InputField::kTagSpoiler = u"||"_q;
|
||||
const QString InputField::kTagBlockquote = u">"_q;
|
||||
const QString InputField::kCustomEmojiTagStart = u"custom-emoji://"_q;
|
||||
const int InputField::kCustomEmojiFormat
|
||||
= QTextFormat::UserObject + 1;
|
||||
const int InputField::kCustomEmojiFormat = QTextFormat::UserObject + 1;
|
||||
const int InputField::kCustomEmojiId = QTextFormat::UserProperty + 7;
|
||||
|
||||
class InputField::Inner final : public QTextEdit {
|
||||
public:
|
||||
|
|
@ -2353,6 +2345,12 @@ void InputField::processFormatting(int insertPosition, int insertEnd) {
|
|||
}
|
||||
}
|
||||
|
||||
void InputField::forceProcessContentsChanges() {
|
||||
PostponeCall(this, [=] {
|
||||
handleContentsChanged();
|
||||
});
|
||||
}
|
||||
|
||||
void InputField::documentContentsChanged(
|
||||
int position,
|
||||
int charsRemoved,
|
||||
|
|
@ -3982,4 +3980,12 @@ rpl::producer<Qt::KeyboardModifiers> InputField::submits() const {
|
|||
|
||||
InputField::~InputField() = default;
|
||||
|
||||
// Optimization: with null page size document does not re-layout
|
||||
// on each insertText / mergeCharFormat.
|
||||
void PrepareFormattingOptimization(not_null<QTextDocument*> document) {
|
||||
if (!document->pageSize().isNull()) {
|
||||
document->setPageSize(QSizeF(0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@
|
|||
#include "ui/text/text_custom_emoji.h"
|
||||
|
||||
#include <QtGui/QTextObjectInterface>
|
||||
#include <QtGui/qtextlayout.h>
|
||||
#include <QtGui/qtextdocument.h>
|
||||
#include <QtGui/qtextcursor.h>
|
||||
|
||||
#include <rpl/variable.h>
|
||||
|
||||
|
|
@ -136,7 +139,8 @@ public:
|
|||
static const QString kTagSpoiler;
|
||||
static const QString kTagBlockquote;
|
||||
static const QString kCustomEmojiTagStart;
|
||||
static const int kCustomEmojiFormat;
|
||||
static const int kCustomEmojiFormat; // QTextFormat::ObjectTypes
|
||||
static const int kCustomEmojiId; // QTextFormat::Property
|
||||
|
||||
InputField(
|
||||
QWidget *parent,
|
||||
|
|
@ -323,6 +327,7 @@ public:
|
|||
[[nodiscard]] rpl::producer<> cancelled() const;
|
||||
[[nodiscard]] rpl::producer<> changes() const;
|
||||
[[nodiscard]] rpl::producer<Qt::KeyboardModifiers> submits() const;
|
||||
void forceProcessContentsChanges();
|
||||
|
||||
~InputField();
|
||||
|
||||
|
|
@ -565,4 +570,6 @@ private:
|
|||
|
||||
};
|
||||
|
||||
void PrepareFormattingOptimization(not_null<QTextDocument*> document);
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue