From bff3291631b738e3239d5860386fdfe9a2755177 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 11 Feb 2021 21:58:25 +0300 Subject: [PATCH] Fixed clearing of text field in sections when sending files. --- .../history_view_compose_controls.cpp | 23 +++++++++++++++++++ .../controls/history_view_compose_controls.h | 2 ++ .../view/history_view_replies_section.cpp | 21 +++-------------- .../view/history_view_scheduled_section.cpp | 21 +++-------------- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index b75d559a6..9b2bc1b74 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -2373,4 +2373,27 @@ void ComposeControls::applyInlineBotQuery( } } +Fn ComposeControls::restoreTextCallback( + const QString &insertTextOnCancel) const { + const auto cursor = _field->textCursor(); + const auto position = cursor.position(); + const auto anchor = cursor.anchor(); + const auto text = getTextWithAppliedMarkdown(); + + _field->setTextWithTags({}); + + return crl::guard(_field, [=] { + _field->setTextWithTags(text); + auto cursor = _field->textCursor(); + cursor.setPosition(anchor); + if (position != anchor) { + cursor.setPosition(position, QTextCursor::KeepAnchor); + } + _field->setTextCursor(cursor); + if (!insertTextOnCancel.isEmpty()) { + _field->textCursor().insertText(insertTextOnCancel); + } + }); +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index 52d49fc55..0919baff7 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -172,6 +172,8 @@ public: void applyDraft( FieldHistoryAction fieldHistoryAction = FieldHistoryAction::Clear); + Fn restoreTextCallback(const QString &insertTextOnCancel) const; + private: enum class TextUpdateEvent { SaveDraft = (1 << 0), diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index e76676f22..a8a96f894 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -626,19 +626,14 @@ bool RepliesWidget::confirmSendingFiles( return false; } - //const auto cursor = _field->textCursor(); - //const auto position = cursor.position(); - //const auto anchor = cursor.anchor(); - const auto text = _composeControls->getTextWithAppliedMarkdown();//_field->getTextWithTags(); using SendLimit = SendFilesBox::SendLimit; auto box = Box( controller(), std::move(list), - text, + _composeControls->getTextWithAppliedMarkdown(), _history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many, Api::SendType::Normal, SendMenu::Type::SilentOnly); // #TODO replies schedule - _composeControls->setText({}); const auto replyTo = replyToId(); box->setConfirmedCallback(crl::guard(this, [=]( @@ -654,18 +649,8 @@ bool RepliesWidget::confirmSendingFiles( options, ctrlShiftEnter); })); - box->setCancelledCallback(crl::guard(this, [=] { - _composeControls->setText(text); - //auto cursor = _field->textCursor(); - //cursor.setPosition(anchor); - //if (position != anchor) { - // cursor.setPosition(position, QTextCursor::KeepAnchor); - //} - //_field->setTextCursor(cursor); - //if (!insertTextOnCancel.isEmpty()) { - // _field->textCursor().insertText(insertTextOnCancel); - //} - })); + box->setCancelledCallback(_composeControls->restoreTextCallback( + insertTextOnCancel)); //ActivateWindow(controller()); const auto shown = Ui::show(std::move(box)); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index f2d11d08e..017956038 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -350,21 +350,16 @@ bool ScheduledWidget::confirmSendingFiles( return false; } - //const auto cursor = _field->textCursor(); - //const auto position = cursor.position(); - //const auto anchor = cursor.anchor(); - const auto text = _composeControls->getTextWithAppliedMarkdown();//_field->getTextWithTags(); using SendLimit = SendFilesBox::SendLimit; auto box = Box( controller(), std::move(list), - text, + _composeControls->getTextWithAppliedMarkdown(), _history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many, CanScheduleUntilOnline(_history->peer) ? Api::SendType::ScheduledToUser : Api::SendType::Scheduled, SendMenu::Type::Disabled); - //_field->setTextWithTags({}); box->setConfirmedCallback(crl::guard(this, [=]( Ui::PreparedList &&list, @@ -379,18 +374,8 @@ bool ScheduledWidget::confirmSendingFiles( options, ctrlShiftEnter); })); - //box->setCancelledCallback(crl::guard(this, [=] { - // _field->setTextWithTags(text); - // auto cursor = _field->textCursor(); - // cursor.setPosition(anchor); - // if (position != anchor) { - // cursor.setPosition(position, QTextCursor::KeepAnchor); - // } - // _field->setTextCursor(cursor); - // if (!insertTextOnCancel.isEmpty()) { - // _field->textCursor().insertText(insertTextOnCancel); - // } - //})); + box->setCancelledCallback(_composeControls->restoreTextCallback( + insertTextOnCancel)); //ActivateWindow(controller()); const auto shown = Ui::show(std::move(box));