diff --git a/Telegram/SourceFiles/history/view/controls/history_view_draft_options.cpp b/Telegram/SourceFiles/history/view/controls/history_view_draft_options.cpp index 9a4b2ba53..307aa0224 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_draft_options.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_draft_options.cpp @@ -99,9 +99,8 @@ public: not_null history); ~PreviewWrap(); - [[nodiscard]] rpl::producer showQuoteSelector( - not_null item, - const TextWithEntities "e); + [[nodiscard]] rpl::producer showQuoteSelector( + const SelectedQuote "e); [[nodiscard]] rpl::producer showLinkSelector( const TextWithTags &message, Data::WebPageDraft webpage, @@ -212,13 +211,13 @@ PreviewWrap::~PreviewWrap() { } } -rpl::producer PreviewWrap::showQuoteSelector( - not_null item, - const TextWithEntities "e) { +rpl::producer PreviewWrap::showQuoteSelector( + const SelectedQuote "e) { _selection.reset(TextSelection()); + const auto item = quote.item; const auto group = item->history()->owner().groups().find(item); - const auto leader = group ? group->items.front() : item; + const auto leader = group ? group->items.front().get() : item; _element = leader->createView(_delegate.get()); _link = _pressedLink = nullptr; @@ -235,10 +234,13 @@ rpl::producer PreviewWrap::showQuoteSelector( initElement(); - _selection = _element->selectionFromQuote(item, quote); + _selection = _element->selectionFromQuote(item, quote.text); return _selection.value( ) | rpl::map([=](TextSelection selection) { - return _element->selectedQuote(selection).text; + if (const auto result = _element->selectedQuote(selection)) { + return result; + } + return SelectedQuote{ item }; }); } @@ -586,7 +588,7 @@ void DraftOptionsBox( struct State { rpl::variable
shown; rpl::lifetime shownLifetime; - rpl::variable quote; + rpl::variable quote; Data::WebPageDraft webpage; WebPageData *preview = nullptr; QString link; @@ -598,7 +600,7 @@ void DraftOptionsBox( rpl::lifetime resolveLifetime; }; const auto state = box->lifetime().make_state(); - state->quote = draft.reply.quote; + state->quote = SelectedQuote{ replyItem, draft.reply.quote }; state->webpage = draft.webpage; state->preview = previewData; state->shown = previewData ? Section::Link : Section::Reply; @@ -636,8 +638,10 @@ void DraftOptionsBox( const auto &highlight = args.highlight; const auto &clearOldDraft = args.clearOldDraft; const auto resolveReply = [=] { + const auto current = state->quote.current(); auto result = draft.reply; - result.quote = state->quote.current(); + result.messageId = current.item->fullId(); + result.quote = current.text; return result; }; const auto finish = [=]( @@ -652,7 +656,8 @@ void DraftOptionsBox( const auto setupReplyActions = [=] { AddFilledSkip(bottom); - if (replyItem->allowsForward()) { + const auto item = state->quote.current().item; + if (item->allowsForward()) { Settings::AddButton( bottom, tr::lng_reply_in_another_chat(), @@ -679,7 +684,7 @@ void DraftOptionsBox( finish({}, state->webpage); }); - if (!replyItem->originalText().empty()) { + if (!item->originalText().empty()) { AddFilledSkip(bottom); Settings::AddDividerText( bottom, @@ -808,7 +813,6 @@ void DraftOptionsBox( state->shownLifetime.destroy(); if (shown == Section::Reply) { state->quote = state->wrap->showQuoteSelector( - replyItem, state->quote.current()); setupReplyActions(); } else { @@ -827,8 +831,8 @@ void DraftOptionsBox( auto save = rpl::combine( state->quote.value(), state->shown.value() - ) | rpl::map([=](const TextWithEntities "e, Section shown) { - return (quote.empty() || shown != Section::Reply) + ) | rpl::map([=](const SelectedQuote "e, Section shown) { + return (quote.text.empty() || shown != Section::Reply) ? tr::lng_settings_save() : tr::lng_reply_quote_selected(); }) | rpl::flatten_latest(); @@ -843,14 +847,20 @@ void DraftOptionsBox( if (replyItem) { args.show->session().data().itemRemoved( ) | rpl::filter([=](not_null removed) { - return removed == replyItem; + const auto current = state->quote.current().item; + if ((removed == replyItem) || (removed == current)) { + return true; + } + const auto group = current->history()->owner().groups().find( + current); + return (group && ranges::contains(group->items, removed)); }) | rpl::start_with_next([=] { if (previewData) { state->tabs = nullptr; box->setPinnedToTopContent( object_ptr(nullptr)); box->setNoContentMargin(false); - box->setTitle(state->quote.current().empty() + box->setTitle(state->quote.current().text.empty() ? tr::lng_reply_options_header() : tr::lng_reply_options_quote()); state->shown = Section::Link; diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 8261628d7..3cd78c711 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -273,6 +273,7 @@ struct SelectedQuote { explicit operator bool() const { return item && !text.empty(); } + friend inline bool operator==(SelectedQuote, SelectedQuote) = default; }; class Element diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp index 402fb4d05..bea617b23 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp @@ -343,6 +343,7 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const { ? Ui::BubbleRounding{ kSmall, kSmall, kSmall, kSmall } : adjustedBubbleRoundingWithCaption(_caption); auto highlight = context.highlight.range; + const auto subpartHighlight = IsSubGroupSelection(highlight); for (auto i = 0, count = int(_parts.size()); i != count; ++i) { const auto &part = _parts[i]; auto partContext = context.withSelection(fullSelection @@ -363,7 +364,7 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const { if (textSelection) { selection = part.content->skipSelection(selection); } - if (!highlighted) { + if (!subpartHighlight) { highlight = part.content->skipSelection(highlight); } if (!part.cache.isNull()) {