From 9c91b03a5b01228a07d9c309fca815b253b1a68a Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 17 Mar 2023 15:57:46 +0400 Subject: [PATCH] Don't cancel caption edit by outside click. --- Telegram/SourceFiles/boxes/edit_caption_box.cpp | 15 ++++++++++++++- Telegram/SourceFiles/boxes/edit_caption_box.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 4cd2a35f7..253d42213 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -67,6 +67,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { +constexpr auto kChangesDebounceTimeout = crl::time(1000); + auto ListFromMimeData(not_null data, bool premium) { using Error = Ui::PreparedList::Error; const auto list = Core::ReadMimeUrls(data); @@ -288,12 +290,23 @@ void EditCaptionBox::setupField() { } void EditCaptionBox::setInitialText() { + const auto initial = PrepareEditText(_historyItem); _field->setTextWithTags( - PrepareEditText(_historyItem), + initial, Ui::InputField::HistoryAction::Clear); auto cursor = _field->textCursor(); cursor.movePosition(QTextCursor::End); _field->setTextCursor(cursor); + + _checkChangedTimer.setCallback([=] { + if (_field->getTextWithAppliedMarkdown() == initial) { + setCloseByOutsideClick(true); + } + }); + connect(_field, &Ui::InputField::changed, [=] { + _checkChangedTimer.callOnce(kChangesDebounceTimeout); + setCloseByOutsideClick(false); + }); } void EditCaptionBox::setupControls() { diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.h b/Telegram/SourceFiles/boxes/edit_caption_box.h index 5a5910f9a..deb756b50 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.h +++ b/Telegram/SourceFiles/boxes/edit_caption_box.h @@ -95,6 +95,7 @@ private: mtpRequestId _saveRequestId = 0; + base::Timer _checkChangedTimer; bool _isPhoto = false; bool _asFile = false;