From 8320feea10e635f6367ade4d32a67240074ff800 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 1 Jun 2020 15:23:19 +0300 Subject: [PATCH] Added saving local text before editing scheduled message. --- .../view/history_view_compose_controls.cpp | 33 ++++++++++++++++--- .../view/history_view_compose_controls.h | 4 +++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp index 664ff3a918..7d85a66093 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp @@ -79,6 +79,10 @@ FieldHeader::FieldHeader(QWidget *parent, not_null data) Ui::DialogTextOptions()); } }, lifetime()); + + _cancel->addClickHandler([=] { + _editMsgId = nullptr; + }); } void FieldHeader::paintEvent(QPaintEvent *e) { @@ -303,11 +307,32 @@ void ComposeControls::init() { }, _wrap->lifetime()); _header->editMsgId( - ) | rpl::start_with_next([=] { + ) | rpl::start_with_next([=](auto item) { updateHeight(); + updateSendButtonType(); + + if (_header->isEditingMessage()) { + setTextFromEditingMessage(item); + } else { + setText(_localSavedText); + _localSavedText = {}; + } }, _wrap->lifetime()); } +void ComposeControls::setTextFromEditingMessage(not_null item) { + if (!_header->isEditingMessage()) { + return; + } + _localSavedText = getTextWithAppliedMarkdown(); + const auto t = item->originalText(); + const auto text = TextWithTags{ + t.text, + TextUtilities::ConvertEntitiesToTextTags(t.entities) + }; + setText(text); +} + void ComposeControls::initField() { _field->setMaxHeight(st::historyComposeFieldMaxHeight); _field->setSubmitSettings(Core::App().settings().sendSubmitWay()); @@ -369,13 +394,13 @@ void ComposeControls::initSendButton() { void ComposeControls::updateSendButtonType() { using Type = Ui::SendButton::Type; const auto type = [&] { - //if (_editMsgId) { - // return Type::Save; + if (_header->isEditingMessage()) { + return Type::Save; //} else if (_isInlineBot) { // return Type::Cancel; //} else if (showRecordButton()) { // return Type::Record; - //} + } return Type::Schedule; }(); _send->setType(type); diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/history_view_compose_controls.h index 9755c42e12..c78794d556 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.h @@ -115,6 +115,8 @@ private: void setTabbedPanel(std::unique_ptr panel); void setText(const TextWithTags &text); + void setTextFromEditingMessage(not_null item); + const not_null _parent; const not_null _window; History *_history = nullptr; @@ -137,6 +139,8 @@ private: rpl::event_stream> _photoChosen; rpl::event_stream _inlineResultChosen; + TextWithTags _localSavedText; + //bool _recording = false; //bool _inField = false; //bool _inReplyEditForward = false;