From 7252e9b26634d613a0ff0a23eeec0a427c8e1d41 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 26 May 2018 18:39:13 +0300 Subject: [PATCH] Apply max length limit to initial text. --- .../SourceFiles/ui/widgets/input_fields.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index 0e96a53da..7f36bc8f4 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -1217,7 +1217,23 @@ void InputField::setAdditionalMargin(int margin) { } void InputField::setMaxLength(int length) { - _maxLength = length; + if (_maxLength != length) { + _maxLength = length; + if (_maxLength > 0) { + const auto document = _inner->document(); + _correcting = true; + QTextCursor(document->docHandle(), 0).joinPreviousEditBlock(); + const auto guard = gsl::finally([&] { + _correcting = false; + QTextCursor(document->docHandle(), 0).endEditBlock(); + handleContentsChanged(); + }); + + auto cursor = QTextCursor(document->docHandle(), 0); + cursor.movePosition(QTextCursor::End); + chopByMaxLength(0, cursor.position()); + } + } } void InputField::setMinHeight(int height) {