From a13ca95894a08e0b2cf466ae4f92f79d3ea3696e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 18 Jan 2025 00:20:46 +0300 Subject: [PATCH] Added initial implementation of search in section for comments. --- .../history_view_compose_controls.cpp | 6 +- .../view/history_view_replies_section.cpp | 64 ++++++++++++++++++- .../view/history_view_replies_section.h | 2 + .../view/history_view_top_bar_widget.cpp | 3 +- 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index ab91da5c2..f801347e2 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1035,13 +1035,15 @@ void ComposeControls::setAutocompleteBoundingRect(QRect rect) { rpl::producer ComposeControls::height() const { using namespace rpl::mappers; return rpl::conditional( - _writeRestriction.value() | rpl::map(!_1), + rpl::combine( + _writeRestriction.value(), + _hidden.value()) | rpl::map(!_1 && !_2), _wrap->heightValue(), rpl::single(_st.attach.height)); } int ComposeControls::heightCurrent() const { - return _writeRestriction.current() + return (_writeRestriction.current() || _hidden.current()) ? _st.attach.height : _wrap->height(); } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 741f3cee8..8fc14b22e 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_replies_section.h" #include "history/view/controls/history_view_compose_controls.h" +#include "history/view/controls/history_view_compose_search.h" #include "history/view/controls/history_view_draft_options.h" #include "history/view/history_view_top_bar_widget.h" #include "history/view/history_view_schedule_box.h" @@ -291,7 +292,9 @@ RepliesWidget::RepliesWidget( }, _topBar->lifetime()); _topBar->searchRequest( ) | rpl::start_with_next([=] { - searchInTopic(); + if (!preventsClose(crl::guard(this, [=]{ searchInTopic(); }))) { + searchInTopic(); + } }, _topBar->lifetime()); controller->adaptive().value( @@ -338,6 +341,9 @@ RepliesWidget::RepliesWidget( } else if (!_joinGroup && canSendReply) { replyToMessage(to); _composeControls->focus(); + if (_composeSearch) { + _composeSearch->hideAnimated(); + } } }, _inner->lifetime()); @@ -2005,7 +2011,11 @@ void RepliesWidget::checkActivation() { } void RepliesWidget::doSetInnerFocus() { - if (!_inner->getSelectedText().rich.text.isEmpty() + if (_composeSearch + && _inner->getSelectedText().rich.text.isEmpty() + && _inner->getSelectedItems().empty()) { + _composeSearch->setInnerFocus(); + } else if (!_inner->getSelectedText().rich.text.isEmpty() || !_inner->getSelectedItems().empty() || !_composeControls->focus()) { _inner->setFocus(); @@ -2441,6 +2451,16 @@ bool RepliesWidget::listScrollTo(int top, bool syntetic) { } void RepliesWidget::listCancelRequest() { + if (_composeSearch) { + if (_inner && + (!_inner->getSelectedItems().empty() + || !_inner->getSelectedText().rich.text.isEmpty())) { + clearSelected(); + } else { + _composeSearch->hideAnimated(); + } + return; + } if (_inner && !_inner->getSelectedItems().empty()) { clearSelected(); return; @@ -2504,6 +2524,9 @@ void RepliesWidget::listSelectionChanged(SelectedItems &&items) { } } _topBar->showSelected(state); + if ((state.count > 0) && _composeSearch) { + _composeSearch->hideAnimated(); + } if (items.empty()) { doSetInnerFocus(); } @@ -2788,7 +2811,9 @@ void RepliesWidget::setupShortcuts() { }) | rpl::start_with_next([=](not_null request) { using Command = Shortcuts::Command; request->check(Command::Search, 1) && request->handle([=] { - searchInTopic(); + if (!preventsClose(crl::guard(this, [=]{ searchInTopic(); }))) { + searchInTopic(); + } return true; }); }, lifetime()); @@ -2797,6 +2822,39 @@ void RepliesWidget::setupShortcuts() { void RepliesWidget::searchInTopic() { if (_topic) { controller()->searchInChat(_topic); + } else { + const auto update = [=] { + if (_composeSearch) { + _composeControls->hide(); + } else { + _composeControls->show(); + } + updateControlsGeometry(); + }; + const auto from = (PeerData*)nullptr; + _composeSearch = std::make_unique( + this, + controller(), + _history, + from); + _composeSearch->setTopMsgId(_rootId); + + update(); + doSetInnerFocus(); + + using Activation = HistoryView::ComposeSearch::Activation; + _composeSearch->activations( + ) | rpl::start_with_next([=](Activation activation) { + showAtPosition(activation.item->position()); + }, _composeSearch->lifetime()); + + _composeSearch->destroyRequests( + ) | rpl::take(1) | rpl::start_with_next([=] { + _composeSearch = nullptr; + + update(); + doSetInnerFocus(); + }, _composeSearch->lifetime()); } } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index 1312eabd7..94f9dfba3 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -64,6 +64,7 @@ class Element; class TopBarWidget; class RepliesMemento; class ComposeControls; +class ComposeSearch; class SendActionPainter; class StickerToast; class TopicReopenBar; @@ -345,6 +346,7 @@ private: object_ptr _topBar; object_ptr _topBarShadow; std::unique_ptr _composeControls; + std::unique_ptr _composeSearch; std::unique_ptr _joinGroup; std::unique_ptr _topicReopenBar; std::unique_ptr _emptyPainter; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index e129816fe..2e9ac641b 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -936,8 +936,7 @@ int TopBarWidget::countSelectedButtonsTop(float64 selectedShown) { void TopBarWidget::updateSearchVisibility() { const auto searchAllowedMode = (_activeChat.section == Section::History) - || (_activeChat.section == Section::Replies - && _activeChat.key.topic()) + || (_activeChat.section == Section::Replies) || (_activeChat.section == Section::SavedSublist && _activeChat.key.sublist()); _search->setVisible(searchAllowedMode && !_chooseForReportReason);