diff --git a/Telegram/SourceFiles/info/profile/tabs/info_profile_tabs_host.cpp b/Telegram/SourceFiles/info/profile/tabs/info_profile_tabs_host.cpp index 1bed7403db..32719f28d6 100644 --- a/Telegram/SourceFiles/info/profile/tabs/info_profile_tabs_host.cpp +++ b/Telegram/SourceFiles/info/profile/tabs/info_profile_tabs_host.cpp @@ -700,13 +700,30 @@ rpl::producer TabsHost::scrollToRequests() const { return _scrollToRequests.events(); } -rpl::producer TabsHost::activeTabBindings() const { +rpl::producer TabsHost::activeTabBindings() { return _activeTab.value( - ) | rpl::map([](MediaTabContent *tab) { - return tab ? tab->topBarBindings() : TabTopBarBindings(); + ) | rpl::map([=](MediaTabContent *tab) { + _searching = false; + auto result = tab ? tab->topBarBindings() : TabTopBarBindings(); + if (auto apply = base::take(result.applySearchQuery)) { + result.applySearchQuery = crl::guard(this, [=](QString query) { + _searching = !query.isEmpty(); + apply(query); + if (_searching) { + scrollToBodyTop(); + } + }); + } + return result; }); } +void TabsHost::scrollToBodyTop() { + if (_visibleTop >= 0) { + _scrollToRequests.fire({ 0, -1 }); + } +} + not_null TabsHost::stripWidget() const { return _strip; } @@ -765,7 +782,9 @@ int TabsHost::resizeGetHeight(int newWidth) { _body->moveToLeft(0, bodyTop); const auto natural = bodyTop + _body->height(); - if (_keepMinHeight + if (_searching && !_scrolledToTop && (natural < _visibleBottom)) { + _keepMinHeight = std::max(_keepMinHeight, _visibleBottom); + } else if (_keepMinHeight && ((natural >= _keepMinHeight) || (natural >= _visibleBottom) || _scrolledToTop)) { diff --git a/Telegram/SourceFiles/info/profile/tabs/info_profile_tabs_host.h b/Telegram/SourceFiles/info/profile/tabs/info_profile_tabs_host.h index d20ad4d3cf..3eca1f313b 100644 --- a/Telegram/SourceFiles/info/profile/tabs/info_profile_tabs_host.h +++ b/Telegram/SourceFiles/info/profile/tabs/info_profile_tabs_host.h @@ -39,7 +39,7 @@ public: ~TabsHost(); [[nodiscard]] rpl::producer activeTabValue() const; - [[nodiscard]] rpl::producer activeTabBindings() const; + [[nodiscard]] rpl::producer activeTabBindings(); [[nodiscard]] rpl::producer scrollToRequests() const; [[nodiscard]] not_null stripWidget() const; @@ -51,6 +51,9 @@ public: [[nodiscard]] QString activeId() const { return _activeId; } + [[nodiscard]] bool searching() const { + return _searching; + } void activateTab(const QString &id, bool animated = true); void restoreActiveTab(const QString &id); @@ -85,6 +88,7 @@ private: void scheduleHeightSync(); void syncBodyNow(); void syncHeightNow(); + void scrollToBodyTop(); [[nodiscard]] QRect bodyVisibleRect() const; void startSlideAnimation( QPixmap wasCache, @@ -118,6 +122,7 @@ private: bool _bodySyncQueued = false; bool _heightSyncQueued = false; bool _scrolledToTop = true; + bool _searching = false; int _keepMinHeight = 0; rpl::variable _activeTab = nullptr;