From c585112e37da9592d19d87f10ec993658a14f646 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 13 Jun 2024 16:33:58 +0400 Subject: [PATCH] Fix jump to archive from search in chat. --- .../SourceFiles/dialogs/dialogs_widget.cpp | 28 ++++++++++++------- Telegram/SourceFiles/dialogs/dialogs_widget.h | 7 ++++- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 9963ee7e98..068c308153 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -346,7 +346,10 @@ Widget::Widget( }, lifetime()); _inner->cancelSearchRequests( ) | rpl::start_with_next([=] { - cancelSearch(true); + cancelSearch({ + .forceFullCancel = true, + .jumpBackToSearchedChat = true, + }); controller->widget()->setInnerFocus(); }, lifetime()); _inner->cancelSearchFromRequests( @@ -418,7 +421,9 @@ Widget::Widget( }, lifetime()); } - _cancelSearch->setClickedCallback([this] { cancelSearch(); }); + _cancelSearch->setClickedCallback([this] { + cancelSearch({ .jumpBackToSearchedChat = true }); + }); _jumpToDate->entity()->setClickedCallback([this] { showCalendar(); }); _chooseFromUser->entity()->setClickedCallback([this] { showSearchFrom(); }); rpl::single(rpl::empty) | rpl::then( @@ -687,7 +692,7 @@ void Widget::setupMoreChatsBar() { controller()->activeChatsFilter( ) | rpl::start_with_next([=](FilterId id) { storiesToggleExplicitExpand(false); - const auto cancelled = cancelSearch(true); + const auto cancelled = cancelSearch({ .forceFullCancel = true }); const auto guard = gsl::finally([&] { if (cancelled) { controller()->content()->dialogsCancelled(); @@ -1162,7 +1167,7 @@ bool Widget::cancelSearchByMouseBack() { return _searchHasFocus && !_searchSuggestionsLocked && !_searchState.inChat - && cancelSearch(); + && cancelSearch({ .jumpBackToSearchedChat = true }); } void Widget::processSearchFocusChange() { @@ -1301,7 +1306,7 @@ void Widget::changeOpenedFolder(Data::Folder *folder, anim::type animated) { return; } changeOpenedSubsection([&] { - cancelSearch(true); + cancelSearch({ .forceFullCancel = true }); closeChildList(anim::type::instant); controller()->closeForum(); _openedFolder = folder; @@ -1355,7 +1360,7 @@ void Widget::changeOpenedForum(Data::Forum *forum, anim::type animated) { return; } changeOpenedSubsection([&] { - cancelSearch(true); + cancelSearch({ .forceFullCancel = true }); closeChildList(anim::type::instant); _openedForum = forum; _searchState.tab = forum @@ -1838,7 +1843,7 @@ void Widget::slideFinished() { } void Widget::escape() { - if (!cancelSearch()) { + if (!cancelSearch({ .jumpBackToSearchedChat = true })) { if (controller()->shownForum().current()) { controller()->closeForum(); } else if (controller()->openedFolder().current()) { @@ -2692,7 +2697,7 @@ void Widget::showForum( changeOpenedForum(forum, params.animated); return; } - cancelSearch(true); + cancelSearch({ .forceFullCancel = true }); openChildList(forum, params); } @@ -3572,10 +3577,11 @@ void Widget::setSearchQuery(const QString &query, int cursorPosition) { } } -bool Widget::cancelSearch(bool forceFullCancel) { +bool Widget::cancelSearch(CancelSearchOptions options) { cancelSearchRequest(); auto updatedState = _searchState; const auto clearingQuery = !updatedState.query.isEmpty(); + const auto forceFullCancel = options.forceFullCancel; auto clearingInChat = (forceFullCancel || !clearingQuery) && (updatedState.inChat || updatedState.fromPeer @@ -3584,7 +3590,9 @@ bool Widget::cancelSearch(bool forceFullCancel) { updatedState.query = QString(); } if (clearingInChat) { - if (updatedState.inChat && controller()->adaptive().isOneColumn()) { + if (options.jumpBackToSearchedChat + && updatedState.inChat + && controller()->adaptive().isOneColumn()) { if (const auto thread = updatedState.inChat.thread()) { controller()->showThread(thread); } else { diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index 29e68a3cca..9a1e736d99 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -131,7 +131,6 @@ public: bool floatPlayerHandleWheelEvent(QEvent *e) override; QRect floatPlayerAvailableRect() override; - bool cancelSearch(bool forceFullCancel = false); bool cancelSearchByMouseBack(); QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; @@ -261,6 +260,12 @@ private: [[nodiscard]] bool redirectKeyToSearch(QKeyEvent *e) const; [[nodiscard]] bool redirectImeToSearch() const; + struct CancelSearchOptions { + bool forceFullCancel = false; + bool jumpBackToSearchedChat = false; + }; + bool cancelSearch(CancelSearchOptions options = {}); + MTP::Sender _api; bool _dragInScroll = false;