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