From 0c8c44728407028a08eb9bd77d69bb57c9bcbbc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 22 Oct 2026 08:54:34 +0200 Subject: [PATCH] Settings: Fix a blank page when reopening settings on the Search tab The saved tab was selected before the Search tab was added, so the index was out of range and no tab was created. Select it after adding Search, and create the current tab anyway if the saved one no longer exists (Search is hidden on small screens). Co-Authored-By: Claude Opus 5.5 (1M context) --- Common/UI/TabHolder.cpp | 4 ++++ UI/TabbedDialogScreen.cpp | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Common/UI/TabHolder.cpp b/Common/UI/TabHolder.cpp index f7da78ad5e..32129466d9 100644 --- a/Common/UI/TabHolder.cpp +++ b/Common/UI/TabHolder.cpp @@ -138,6 +138,10 @@ bool TabHolder::EnsureTab(int index) { void TabHolder::SetInitialTab(int tab) { if (tab < 0 || tab >= (int)tabs_.size()) { + // The tab may no longer exist (the search tab is hidden on small screens, for example). + if (currentTab_ < (int)tabs_.size()) { + EnsureTab(currentTab_); + } return; } EnsureTab(tab); diff --git a/UI/TabbedDialogScreen.cpp b/UI/TabbedDialogScreen.cpp index ca626a7760..81eae5bc48 100644 --- a/UI/TabbedDialogScreen.cpp +++ b/UI/TabbedDialogScreen.cpp @@ -114,11 +114,6 @@ void UITabbedBaseDialogScreen::CreateViews() { // Let the subclass create its tabs. CreateTabs(); - if (currentTabSetting_) { - tabHolder_->SetInitialTab(*currentTabSetting_); - } else { - tabHolder_->EnsureTab(tabHolder_->GetCurrentTab()); - } tabHolder_->OnChangeTab.Add([this](UI::EventParams &e) { if (currentTabSetting_) { @@ -151,6 +146,13 @@ void UITabbedBaseDialogScreen::CreateViews() { } } + // After the search tab, which the saved tab can be. + if (currentTabSetting_) { + tabHolder_->SetInitialTab(*currentTabSetting_); + } else { + tabHolder_->EnsureTab(tabHolder_->GetCurrentTab()); + } + // Need to handle recreates, both important and accidental ones. if (!searchFilter_.empty()) { ApplySearchFilter();