From 5bd17ae1b2de5b38f30ab8c99d6ad72be25aa803 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 22 Apr 2021 23:39:41 +0300 Subject: [PATCH] Fixed caption area height in EditCaptionBox. Regression was introduced in 51f960442e. --- Telegram/SourceFiles/boxes/boxes.style | 1 + .../SourceFiles/boxes/edit_caption_box.cpp | 24 +++++++++++++++++++ Telegram/SourceFiles/boxes/edit_caption_box.h | 1 + 3 files changed, 26 insertions(+) diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index dbf4384fb..3f75569ed 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -382,6 +382,7 @@ confirmCaptionArea: InputField(defaultInputField) { textMargins: margins(1px, 26px, 31px, 4px); heightMax: 158px; } +confirmEditCaptionAreaHeightMax: 78px; confirmBg: windowBgOver; confirmMaxHeight: 245px; confirmMaxHeightSkip: 25px; diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index ef5c71645..9a919c24c 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -660,6 +660,7 @@ void EditCaptionBox::updateEditPreview() { } } updateEditMediaButton(); + updateCaptionMaxHeight(); captionResized(); } @@ -783,6 +784,7 @@ void EditCaptionBox::prepare() { auto cursor = _field->textCursor(); cursor.movePosition(QTextCursor::End); _field->setTextCursor(cursor); + updateCaptionMaxHeight(); setupDragArea(); } @@ -826,6 +828,28 @@ void EditCaptionBox::captionResized() { update(); } +void EditCaptionBox::updateCaptionMaxHeight() { + // Save. + const auto wasCursor = _field->textCursor(); + const auto position = wasCursor.position(); + const auto anchor = wasCursor.anchor(); + const auto text = _field->getTextWithAppliedMarkdown(); + _field->setTextWithTags({}); + + _field->setMaxHeight(_doc + ? st::confirmCaptionArea.heightMax + : st::confirmEditCaptionAreaHeightMax); + + // Restore. + _field->setTextWithTags(text); + auto cursor = _field->textCursor(); + cursor.setPosition(anchor); + if (position != anchor) { + cursor.setPosition(position, QTextCursor::KeepAnchor); + } + _field->setTextCursor(cursor); +} + void EditCaptionBox::setupEmojiPanel() { const auto container = getDelegate()->outerContainer(); _emojiPanel = base::make_unique_q( diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.h b/Telegram/SourceFiles/boxes/edit_caption_box.h index e0e4b46e8..8f619eece 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.h +++ b/Telegram/SourceFiles/boxes/edit_caption_box.h @@ -91,6 +91,7 @@ private: bool fileFromClipboard(not_null data); void updateEditPreview(); void updateEditMediaButton(); + void updateCaptionMaxHeight(); int errorTopSkip() const;