Fix jump to archive from search in chat.

This commit is contained in:
John Preston 2024-06-13 16:33:58 +04:00
parent 392df8b56f
commit c585112e37
2 changed files with 24 additions and 11 deletions

View File

@ -346,7 +346,10 @@ Widget::Widget(
}, lifetime()); }, lifetime());
_inner->cancelSearchRequests( _inner->cancelSearchRequests(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
cancelSearch(true); cancelSearch({
.forceFullCancel = true,
.jumpBackToSearchedChat = true,
});
controller->widget()->setInnerFocus(); controller->widget()->setInnerFocus();
}, lifetime()); }, lifetime());
_inner->cancelSearchFromRequests( _inner->cancelSearchFromRequests(
@ -418,7 +421,9 @@ Widget::Widget(
}, lifetime()); }, lifetime());
} }
_cancelSearch->setClickedCallback([this] { cancelSearch(); }); _cancelSearch->setClickedCallback([this] {
cancelSearch({ .jumpBackToSearchedChat = true });
});
_jumpToDate->entity()->setClickedCallback([this] { showCalendar(); }); _jumpToDate->entity()->setClickedCallback([this] { showCalendar(); });
_chooseFromUser->entity()->setClickedCallback([this] { showSearchFrom(); }); _chooseFromUser->entity()->setClickedCallback([this] { showSearchFrom(); });
rpl::single(rpl::empty) | rpl::then( rpl::single(rpl::empty) | rpl::then(
@ -687,7 +692,7 @@ void Widget::setupMoreChatsBar() {
controller()->activeChatsFilter( controller()->activeChatsFilter(
) | rpl::start_with_next([=](FilterId id) { ) | rpl::start_with_next([=](FilterId id) {
storiesToggleExplicitExpand(false); storiesToggleExplicitExpand(false);
const auto cancelled = cancelSearch(true); const auto cancelled = cancelSearch({ .forceFullCancel = true });
const auto guard = gsl::finally([&] { const auto guard = gsl::finally([&] {
if (cancelled) { if (cancelled) {
controller()->content()->dialogsCancelled(); controller()->content()->dialogsCancelled();
@ -1162,7 +1167,7 @@ bool Widget::cancelSearchByMouseBack() {
return _searchHasFocus return _searchHasFocus
&& !_searchSuggestionsLocked && !_searchSuggestionsLocked
&& !_searchState.inChat && !_searchState.inChat
&& cancelSearch(); && cancelSearch({ .jumpBackToSearchedChat = true });
} }
void Widget::processSearchFocusChange() { void Widget::processSearchFocusChange() {
@ -1301,7 +1306,7 @@ void Widget::changeOpenedFolder(Data::Folder *folder, anim::type animated) {
return; return;
} }
changeOpenedSubsection([&] { changeOpenedSubsection([&] {
cancelSearch(true); cancelSearch({ .forceFullCancel = true });
closeChildList(anim::type::instant); closeChildList(anim::type::instant);
controller()->closeForum(); controller()->closeForum();
_openedFolder = folder; _openedFolder = folder;
@ -1355,7 +1360,7 @@ void Widget::changeOpenedForum(Data::Forum *forum, anim::type animated) {
return; return;
} }
changeOpenedSubsection([&] { changeOpenedSubsection([&] {
cancelSearch(true); cancelSearch({ .forceFullCancel = true });
closeChildList(anim::type::instant); closeChildList(anim::type::instant);
_openedForum = forum; _openedForum = forum;
_searchState.tab = forum _searchState.tab = forum
@ -1838,7 +1843,7 @@ void Widget::slideFinished() {
} }
void Widget::escape() { void Widget::escape() {
if (!cancelSearch()) { if (!cancelSearch({ .jumpBackToSearchedChat = true })) {
if (controller()->shownForum().current()) { if (controller()->shownForum().current()) {
controller()->closeForum(); controller()->closeForum();
} else if (controller()->openedFolder().current()) { } else if (controller()->openedFolder().current()) {
@ -2692,7 +2697,7 @@ void Widget::showForum(
changeOpenedForum(forum, params.animated); changeOpenedForum(forum, params.animated);
return; return;
} }
cancelSearch(true); cancelSearch({ .forceFullCancel = true });
openChildList(forum, params); 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(); cancelSearchRequest();
auto updatedState = _searchState; auto updatedState = _searchState;
const auto clearingQuery = !updatedState.query.isEmpty(); const auto clearingQuery = !updatedState.query.isEmpty();
const auto forceFullCancel = options.forceFullCancel;
auto clearingInChat = (forceFullCancel || !clearingQuery) auto clearingInChat = (forceFullCancel || !clearingQuery)
&& (updatedState.inChat && (updatedState.inChat
|| updatedState.fromPeer || updatedState.fromPeer
@ -3584,7 +3590,9 @@ bool Widget::cancelSearch(bool forceFullCancel) {
updatedState.query = QString(); updatedState.query = QString();
} }
if (clearingInChat) { if (clearingInChat) {
if (updatedState.inChat && controller()->adaptive().isOneColumn()) { if (options.jumpBackToSearchedChat
&& updatedState.inChat
&& controller()->adaptive().isOneColumn()) {
if (const auto thread = updatedState.inChat.thread()) { if (const auto thread = updatedState.inChat.thread()) {
controller()->showThread(thread); controller()->showThread(thread);
} else { } else {

View File

@ -131,7 +131,6 @@ public:
bool floatPlayerHandleWheelEvent(QEvent *e) override; bool floatPlayerHandleWheelEvent(QEvent *e) override;
QRect floatPlayerAvailableRect() override; QRect floatPlayerAvailableRect() override;
bool cancelSearch(bool forceFullCancel = false);
bool cancelSearchByMouseBack(); bool cancelSearchByMouseBack();
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
@ -261,6 +260,12 @@ private:
[[nodiscard]] bool redirectKeyToSearch(QKeyEvent *e) const; [[nodiscard]] bool redirectKeyToSearch(QKeyEvent *e) const;
[[nodiscard]] bool redirectImeToSearch() const; [[nodiscard]] bool redirectImeToSearch() const;
struct CancelSearchOptions {
bool forceFullCancel = false;
bool jumpBackToSearchedChat = false;
};
bool cancelSearch(CancelSearchOptions options = {});
MTP::Sender _api; MTP::Sender _api;
bool _dragInScroll = false; bool _dragInScroll = false;