From e57c8ba756cdfb7bd6a3ee7199a3a3fe88bf80b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 10 Nov 2026 13:00:17 +0100 Subject: [PATCH] Settings: Clicking the current tab goes back up to its root page Co-Authored-By: Claude Opus 5.5 --- Common/UI/TabHolder.cpp | 7 +++++++ Common/UI/TabHolder.h | 2 ++ UI/SettingsPagesDialogScreen.cpp | 14 ++++++++++++++ UI/SettingsPagesDialogScreen.h | 1 + UI/TabbedDialogScreen.cpp | 3 +++ UI/TabbedDialogScreen.h | 2 ++ 6 files changed, 29 insertions(+) diff --git a/Common/UI/TabHolder.cpp b/Common/UI/TabHolder.cpp index e540f08f2b..e46219c5ae 100644 --- a/Common/UI/TabHolder.cpp +++ b/Common/UI/TabHolder.cpp @@ -244,6 +244,13 @@ void TabHolder::OnTabClick(EventParams &e) { // We have e.b set when it was an explicit click action. // In that case, we make the view gone and then visible - this scrolls scrollviews to the top. if (e.b != 0) { + if ((int)e.a == currentTab_) { + UI::EventParams e2{}; + e2.v = this; + e2.a = currentTab_; + OnReselectTab.Trigger(e2); + return; + } // SetCurrentTab calls EnsureTab if needed. SetCurrentTab((int)e.a); } diff --git a/Common/UI/TabHolder.h b/Common/UI/TabHolder.h index bedbf32e4b..9f9900eae2 100644 --- a/Common/UI/TabHolder.h +++ b/Common/UI/TabHolder.h @@ -53,6 +53,8 @@ public: bool EnsureTab(int index); // return true if it actually created a tab. Event OnChangeTab; + // A click on the tab that's already shown. + Event OnReselectTab; private: void AddTabContents(std::string_view title, ImageID imageId, ViewGroup *tabContents); diff --git a/UI/SettingsPagesDialogScreen.cpp b/UI/SettingsPagesDialogScreen.cpp index 5a7e19d0f5..32159cbdd7 100644 --- a/UI/SettingsPagesDialogScreen.cpp +++ b/UI/SettingsPagesDialogScreen.cpp @@ -594,3 +594,17 @@ int SettingsPagesDialogScreen::InitialTab() { void SettingsPagesDialogScreen::TabChanged(int tab) { SetSearchText(""); } + +// Picking the tab that's shown leaves the search, and goes back up to the tab's root page. +void SettingsPagesDialogScreen::TabReselected(int tab) { + SetSearchText(""); + int settingsTab = CurrentSettingsTab(); + if (settingsTab < 0) { + return; + } + const std::vector &path = pagePaths_[settingsTabs_[settingsTab].tag]; + if (path.empty()) { + return; + } + ShowPage(settingsTab, {}, path[0]); // Focuses the link to the page we're leaving. +} diff --git a/UI/SettingsPagesDialogScreen.h b/UI/SettingsPagesDialogScreen.h index 36d74fc7c4..d50979a189 100644 --- a/UI/SettingsPagesDialogScreen.h +++ b/UI/SettingsPagesDialogScreen.h @@ -58,6 +58,7 @@ protected: // with the page, like lists read from disk, doesn't need to be read again. bool RecreatingForPageChange() const { return pageChange_; } void TabChanged(int tab) override; + void TabReselected(int tab) override; // Whether there's a way to type a search. static bool CanShowSearch(); diff --git a/UI/TabbedDialogScreen.cpp b/UI/TabbedDialogScreen.cpp index 85ebbcec4f..7a297e639a 100644 --- a/UI/TabbedDialogScreen.cpp +++ b/UI/TabbedDialogScreen.cpp @@ -111,6 +111,9 @@ void UITabbedBaseDialogScreen::CreateViews() { } TabChanged(e.a); }); + tabHolder_->OnReselectTab.Add([this](UI::EventParams &e) { + TabReselected(e.a); + }); int initialTab = InitialTab(); if (initialTab >= 0) { diff --git a/UI/TabbedDialogScreen.h b/UI/TabbedDialogScreen.h index 563c537123..5616163a4c 100644 --- a/UI/TabbedDialogScreen.h +++ b/UI/TabbedDialogScreen.h @@ -50,6 +50,8 @@ protected: // The tab to show first, after CreateTabs, if not the saved one (-1). virtual int InitialTab() { return -1; } virtual void TabChanged(int tab) {} + // The tab already shown was clicked. + virtual void TabReselected(int tab) {} int GetCurrentTab() const; void SetCurrentTab(int tab);