Added initial implementation of search in section for comments.

This commit is contained in:
23rd 2025-01-18 00:20:46 +03:00
parent 0989a80a57
commit a13ca95894
4 changed files with 68 additions and 7 deletions

View file

@ -1035,13 +1035,15 @@ void ComposeControls::setAutocompleteBoundingRect(QRect rect) {
rpl::producer<int> 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();
}

View file

@ -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<Shortcuts::Request*> 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<HistoryView::ComposeSearch>(
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());
}
}

View file

@ -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<TopBarWidget> _topBar;
object_ptr<Ui::PlainShadow> _topBarShadow;
std::unique_ptr<ComposeControls> _composeControls;
std::unique_ptr<ComposeSearch> _composeSearch;
std::unique_ptr<Ui::FlatButton> _joinGroup;
std::unique_ptr<TopicReopenBar> _topicReopenBar;
std::unique_ptr<EmptyPainter> _emptyPainter;

View file

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