Close chats search when selecting a folder.

This commit is contained in:
John Preston 2024-06-03 17:13:14 +04:00
parent e8a929bdbd
commit 23a13ab54e
2 changed files with 15 additions and 11 deletions

View File

@ -675,9 +675,12 @@ void Widget::setupMoreChatsBar() {
controller()->activeChatsFilter( controller()->activeChatsFilter(
) | rpl::start_with_next([=](FilterId id) { ) | rpl::start_with_next([=](FilterId id) {
storiesToggleExplicitExpand(false); storiesToggleExplicitExpand(false);
if (!_searchState.inChat) { const auto cancelled = cancelSearch(true);
cancelSearch(); const auto guard = gsl::finally([&] {
} if (cancelled) {
controller()->content()->dialogsCancelled();
}
});
if (!id) { if (!id) {
_moreChatsBar = nullptr; _moreChatsBar = nullptr;
@ -1385,7 +1388,7 @@ void Widget::changeOpenedFolder(Data::Folder *folder, anim::type animated) {
return; return;
} }
changeOpenedSubsection([&] { changeOpenedSubsection([&] {
cancelSearch(); cancelSearch(true);
closeChildList(anim::type::instant); closeChildList(anim::type::instant);
controller()->closeForum(); controller()->closeForum();
_openedFolder = folder; _openedFolder = folder;
@ -1439,7 +1442,7 @@ void Widget::changeOpenedForum(Data::Forum *forum, anim::type animated) {
return; return;
} }
changeOpenedSubsection([&] { changeOpenedSubsection([&] {
cancelSearch(); cancelSearch(true);
closeChildList(anim::type::instant); closeChildList(anim::type::instant);
_openedForum = forum; _openedForum = forum;
_searchState.tab = forum _searchState.tab = forum
@ -2777,7 +2780,7 @@ void Widget::showForum(
changeOpenedForum(forum, params.animated); changeOpenedForum(forum, params.animated);
return; return;
} }
cancelSearch(); cancelSearch(true);
openChildList(forum, params); openChildList(forum, params);
} }
@ -3652,17 +3655,18 @@ void Widget::setSearchQuery(const QString &query, int cursorPosition) {
} }
} }
bool Widget::cancelSearch() { bool Widget::cancelSearch(bool forceFullCancel) {
cancelSearchRequest(); cancelSearchRequest();
auto updatedState = _searchState; auto updatedState = _searchState;
const auto clearingQuery = !updatedState.query.isEmpty(); const auto clearingQuery = !updatedState.query.isEmpty();
auto clearingInChat = !clearingQuery auto clearingInChat = (forceFullCancel || !clearingQuery)
&& (updatedState.inChat && (updatedState.inChat
|| updatedState.fromPeer || updatedState.fromPeer
|| !updatedState.tags.empty()); || !updatedState.tags.empty());
if (clearingQuery) { if (clearingQuery) {
updatedState.query = QString(); updatedState.query = QString();
} else if (clearingInChat) { }
if (clearingInChat) {
if (updatedState.inChat && controller()->adaptive().isOneColumn()) { if (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);
@ -3680,7 +3684,7 @@ bool Widget::cancelSearch() {
setInnerFocus(true); setInnerFocus(true);
clearingInChat = true; clearingInChat = true;
} }
const auto clearSearchFocus = !updatedState.inChat const auto clearSearchFocus = (forceFullCancel || !updatedState.inChat)
&& (_searchHasFocus || _searchSuggestionsLocked); && (_searchHasFocus || _searchSuggestionsLocked);
if (!updatedState.inChat && _suggestions) { if (!updatedState.inChat && _suggestions) {
_suggestions->clearPersistance(); _suggestions->clearPersistance();

View File

@ -131,7 +131,7 @@ public:
bool floatPlayerHandleWheelEvent(QEvent *e) override; bool floatPlayerHandleWheelEvent(QEvent *e) override;
QRect floatPlayerAvailableRect() override; QRect floatPlayerAvailableRect() override;
bool cancelSearch(); bool cancelSearch(bool forceFullCancel = false);
bool cancelSearchByMouseBack(); bool cancelSearchByMouseBack();
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;