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());
_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 {

View File

@ -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;