From 435482eece7f78de876a134febc843e620e0bd34 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 1 Jul 2026 11:01:37 +0400 Subject: [PATCH] Open the editor in edit mode from Expand --- .../SourceFiles/history/history_widget.cpp | 13 +++++ .../history_view_compose_controls.cpp | 12 ++++ .../iv/editor/iv_editor_session.cpp | 57 +++++++++++++++++++ .../SourceFiles/iv/editor/iv_editor_session.h | 5 ++ 4 files changed, 87 insertions(+) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index d40be61941..f8902fb086 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1404,6 +1404,19 @@ void HistoryWidget::initExpandButton() { return; } const auto window = controller(); + if (editingMessage()) { + const auto item = session().data().message( + _history->peer, + _editMsgId); + if (item && Iv::Editor::CheckRichMessagesPremium(window)) { + Iv::Editor::ShowEditFromFieldBox( + window, + item, + prepareSendAction({}), + [=] { return sendMenuDetails(); }); + } + return; + } Iv::Editor::ShowComposeBox( window, _history->peer, 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 929661ef35..09064a1a41 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -3730,6 +3730,18 @@ void ComposeControls::initExpandButton() { if (!_regularWindow || !_history || !_sendActionFactory) { return; } + if (isEditingMessage()) { + const auto item = _history->owner().message( + _header->editMsgId()); + if (item && Iv::Editor::CheckRichMessagesPremium(_regularWindow)) { + Iv::Editor::ShowEditFromFieldBox( + _regularWindow, + item, + _sendActionFactory(), + [=] { return sendMenuDetails(); }); + } + return; + } Iv::Editor::ShowComposeBox( _regularWindow, _history->peer, diff --git a/Telegram/SourceFiles/iv/editor/iv_editor_session.cpp b/Telegram/SourceFiles/iv/editor/iv_editor_session.cpp index fc2071f26e..b68011e03d 100644 --- a/Telegram/SourceFiles/iv/editor/iv_editor_session.cpp +++ b/Telegram/SourceFiles/iv/editor/iv_editor_session.cpp @@ -643,6 +643,52 @@ public: articleSession->showWindow(); } + static void ShowEditFromField( + not_null item, + Api::SendAction action, + Fn sendMenuDetails) { + const auto session = &item->history()->session(); + const auto topicRootId = action.replyTo.topicRootId; + const auto monoforumPeerId = action.replyTo.monoforumPeerId; + const auto composeKey = ComposeKey( + session, + item->history()->peer->id, + topicRootId, + monoforumPeerId); + auto page = std::make_shared(); + if (const auto entry = LookupComposeThreadEntry(composeKey)) { + if (entry->readDraft) { + if (const auto draft = entry->readDraft()) { + const auto &withTags = draft->textWithTags; + *page = SplitTextIntoRichPage({ + withTags.text, + TextUtilities::ConvertTextTagsToEntities( + withTags.tags), + }); + } + } + if (entry->migratedAway) { + entry->migratedAway(); + } + } + auto articleSession = std::shared_ptr(new ArticleSession( + session, + item->history()->peer, + Mode::Edit, + item->fullId(), + std::move(page), + std::move(action), + std::move(sendMenuDetails), + EditedItemSnapshot{ + .item = item, + .inlinePage = item->richPage(), + .summary = item->originalText(), + .fullPage = item->fullRichPage(), + }, + std::nullopt)); + articleSession->showWindow(); + } + ~ArticleSession() { _submitDeferred = false; for (const auto &attachment : _attachments) { @@ -4112,6 +4158,17 @@ void ShowEditBox( }); } +void ShowEditFromFieldBox( + not_null controller, + not_null item, + Api::SendAction action, + Fn sendMenuDetails) { + ArticleSession::ShowEditFromField( + item, + std::move(action), + std::move(sendMenuDetails)); +} + bool IsComposeBoxOpen( not_null session, PeerId peerId, diff --git a/Telegram/SourceFiles/iv/editor/iv_editor_session.h b/Telegram/SourceFiles/iv/editor/iv_editor_session.h index 151849f265..6875d701a5 100644 --- a/Telegram/SourceFiles/iv/editor/iv_editor_session.h +++ b/Telegram/SourceFiles/iv/editor/iv_editor_session.h @@ -59,6 +59,11 @@ void ShowComposeBox( void ShowEditBox( not_null controller, not_null item); +void ShowEditFromFieldBox( + not_null controller, + not_null item, + Api::SendAction action, + Fn sendMenuDetails); [[nodiscard]] bool IsComposeBoxOpen( not_null session, PeerId peerId,