Restore settings search query on return.

This commit is contained in:
John Preston
2026-01-16 12:10:17 +04:00
parent 4c2e73a3ae
commit fafe2f96c1
4 changed files with 33 additions and 24 deletions

View File

@@ -1580,6 +1580,8 @@ PRIVATE
settings/sections/settings_main.h
settings/settings_search.cpp
settings/settings_search.h
settings/settings_faq_suggestions.cpp
settings/settings_faq_suggestions.h
settings/settings_builder.cpp
settings/settings_builder.h
settings/sections/settings_notifications.cpp

View File

@@ -151,6 +151,10 @@ void FaqSuggestions::parse(const MTPDwebPage &page) {
}, [&](const MTPDpageBlockHeader &) {
inToc = false;
}, [&](const auto &) {});
if (!inToc && !_entries.empty()) {
break;
}
}
}

View File

@@ -170,14 +170,17 @@ base::weak_qptr<Ui::RpWidget> Search::createPinnedToTop(
rebuildResults(std::move(query));
}, searchContainer->lifetime());
if (!_pendingQuery.isEmpty()) {
_searchController->setQuery(base::take(_pendingQuery));
}
return base::make_weak(not_null<Ui::RpWidget*>{ searchContainer });
}
void Search::setupContent() {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
_resultsContainer = content->add(
object_ptr<Ui::VerticalLayout>(content));
_list = content->add(object_ptr<Ui::VerticalLayout>(content));
setupCustomizations();
buildIndex();
@@ -241,15 +244,10 @@ void Search::buildIndex() {
}
void Search::rebuildResults(const QString &query) {
for (const auto &[index, button] : _buttonCache) {
button->setParent(this);
button->hide();
for (auto i = 0, count = _list->count(); i != count; ++i) {
_list->widgetAt(i)->hide();
}
for (const auto &button : _faqButtons) {
button->setParent(this);
button->hide();
}
_resultsContainer->clear();
_list->clear();
const auto queryWords = TextUtilities::PrepareSearchWords(query);
@@ -309,9 +307,9 @@ void Search::rebuildResults(const QString &query) {
}
if (results.empty() && !queryWords.isEmpty()) {
_resultsContainer->add(
_list->add(
object_ptr<Ui::FlatLabel>(
_resultsContainer,
_list,
tr::lng_search_tab_no_results(),
st::settingsSearchNoResults),
st::settingsSearchNoResultsPadding);
@@ -327,7 +325,7 @@ void Search::rebuildResults(const QString &query) {
if (cached != _buttonCache.end()) {
const auto button = cached->second;
button->show();
_resultsContainer->add(
_list->add(
object_ptr<Ui::SettingsButton>::fromRaw(button));
continue;
}
@@ -357,7 +355,9 @@ void Search::rebuildResults(const QString &query) {
subtitle,
st,
IconDescriptor{ entry.icon.icon },
hasCheckIcon ? entry.checkIcon : Builder::SearchEntryCheckIcon::None);
(hasCheckIcon
? entry.checkIcon
: Builder::SearchEntryCheckIcon::None));
if (custom && custom->hook) {
custom->hook(button);
@@ -380,20 +380,23 @@ void Search::rebuildResults(const QString &query) {
});
_buttonCache.emplace(entryIndex, button);
_resultsContainer->add(
object_ptr<Ui::SettingsButton>::fromRaw(button));
_list->add(object_ptr<Ui::SettingsButton>::fromRaw(button));
}
}
_resultsContainer->resizeToWidth(_resultsContainer->width());
_list->resizeToWidth(_list->width());
}
void Search::setStepDataReference(std::any &data) {
_stepData = &data;
if (_stepData->has_value() && _searchController) {
if (_stepData->has_value()) {
const auto state = std::any_cast<SearchSectionState>(_stepData);
if (state && !state->query.isEmpty()) {
_searchController->setQuery(state->query);
if (_searchController) {
_searchController->setQuery(state->query);
} else {
_pendingQuery = state->query;
}
}
}
}
@@ -419,8 +422,8 @@ void Search::rebuildFaqResults() {
this,
entry.title,
subtitle,
st::settingsSearchResult,
IconDescriptor{ &st::menuIconFaq },
st::settingsSearchResultNoIcon,
IconDescriptor{},
Builder::SearchEntryCheckIcon::None);
_faqButtons.push_back(button);
}
@@ -436,12 +439,12 @@ void Search::rebuildFaqResults() {
});
button->show();
_resultsContainer->add(object_ptr<Ui::SettingsButton>::fromRaw(button));
_list->add(object_ptr<Ui::SettingsButton>::fromRaw(button));
++index;
}
_resultsContainer->resizeToWidth(_resultsContainer->width());
_list->resizeToWidth(_list->width());
}
} // namespace Settings

View File

@@ -61,7 +61,7 @@ private:
std::unique_ptr<Ui::SearchFieldController> _searchController;
Ui::InputField *_searchField = nullptr;
Ui::VerticalLayout *_resultsContainer = nullptr;
Ui::VerticalLayout *_list = nullptr;
base::flat_map<QString, ResultCustomization> _customizations;
std::any *_stepData = nullptr;
QString _pendingQuery;