@@ -297,7 +297,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
297297 // extract ElementToFocus and clear it; we only want to use it once
298298 auto vmImpl = get_self<ColorSchemesPageViewModel>(_colorSchemesPageVM);
299299 const auto elementToFocus = vmImpl->ElementToFocus ();
300- vmImpl->ElementToFocus (L" " );
300+ vmImpl->ElementToFocus ({} );
301301
302302 const auto currentScheme = _colorSchemesPageVM.CurrentScheme ();
303303 if (_colorSchemesPageVM.CurrentPage () == ColorSchemesSubPage::EditColorScheme && currentScheme)
@@ -634,31 +634,37 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
634634 const auto settingName{ args.PropertyName () };
635635 if (settingName == L" CurrentPage" )
636636 {
637+ // extract ElementToFocus and clear it; we only want to use it once
638+ auto vmImpl = get_self<ProfileViewModel>(profile);
639+ const auto elementToFocus = vmImpl->ElementToFocus ();
640+ vmImpl->ElementToFocus ({});
641+
637642 const auto currentPage = profile.CurrentPage ();
638643 if (currentPage == ProfileSubPage::Base)
639644 {
640- contentFrame ().Navigate (xaml_typename<Editor::Profiles_Base>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this ));
645+ contentFrame ().Navigate (xaml_typename<Editor::Profiles_Base>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this , elementToFocus ));
641646 _breadcrumbs.Clear ();
642647 const auto crumb = winrt::make<Breadcrumb>(breadcrumbTag, breadcrumbText, BreadcrumbSubPage::None);
643648 _breadcrumbs.Append (crumb);
649+ SettingsMainPage_ScrollViewer ().ScrollToVerticalOffset (0 );
644650 }
645651 else if (currentPage == ProfileSubPage::Appearance)
646652 {
647- contentFrame ().Navigate (xaml_typename<Editor::Profiles_Appearance>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this ));
653+ contentFrame ().Navigate (xaml_typename<Editor::Profiles_Appearance>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this , elementToFocus ));
648654 const auto crumb = winrt::make<Breadcrumb>(breadcrumbTag, RS_ (L" Profile_Appearance/Header" ), BreadcrumbSubPage::Profile_Appearance);
649655 _breadcrumbs.Append (crumb);
650656 SettingsMainPage_ScrollViewer ().ScrollToVerticalOffset (0 );
651657 }
652658 else if (currentPage == ProfileSubPage::Terminal)
653659 {
654- contentFrame ().Navigate (xaml_typename<Editor::Profiles_Terminal>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this ));
660+ contentFrame ().Navigate (xaml_typename<Editor::Profiles_Terminal>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this , elementToFocus ));
655661 const auto crumb = winrt::make<Breadcrumb>(breadcrumbTag, RS_ (L" Profile_Terminal/Header" ), BreadcrumbSubPage::Profile_Terminal);
656662 _breadcrumbs.Append (crumb);
657663 SettingsMainPage_ScrollViewer ().ScrollToVerticalOffset (0 );
658664 }
659665 else if (currentPage == ProfileSubPage::Advanced)
660666 {
661- contentFrame ().Navigate (xaml_typename<Editor::Profiles_Advanced>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this ));
667+ contentFrame ().Navigate (xaml_typename<Editor::Profiles_Advanced>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this , elementToFocus ));
662668 const auto crumb = winrt::make<Breadcrumb>(breadcrumbTag, RS_ (L" Profile_Advanced/Header" ), BreadcrumbSubPage::Profile_Advanced);
663669 _breadcrumbs.Append (crumb);
664670 SettingsMainPage_ScrollViewer ().ScrollToVerticalOffset (0 );
@@ -844,23 +850,38 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
844850 SettingsNav ().SelectedItem (profileNavItem);
845851 }
846852
853+ // Pass along the element to focus to the ProfileViewModel.
854+ // This will work as a staging area before we navigate to the correct sub-page
855+ auto profileVMImpl = get_self<ProfileViewModel>(profile);
856+ profileVMImpl->ElementToFocus (elementToFocus);
857+
858+ // convert the BreadcrumbSubPage to ProfileSubPage
859+ const ProfileSubPage profileSubPage = [&](BreadcrumbSubPage subPage) {
860+ switch (subPage)
861+ {
862+ case BreadcrumbSubPage::None:
863+ return ProfileSubPage::Base;
864+ case BreadcrumbSubPage::Profile_Appearance:
865+ return ProfileSubPage::Appearance;
866+ case BreadcrumbSubPage::Profile_Terminal:
867+ return ProfileSubPage::Terminal;
868+ case BreadcrumbSubPage::Profile_Advanced:
869+ return ProfileSubPage::Advanced;
870+ default :
871+ // This should never happen
872+ assert (false );
873+ }
874+ }(subPage);
875+ const bool needsForcedRefresh = profile.CurrentPage () == profileSubPage;
876+
847877 // Set the profile's 'CurrentPage' to the correct one, if this requires further navigation, the
848878 // event handler will do it
849- if (subPage == BreadcrumbSubPage::None)
850- {
851- profile.CurrentPage (ProfileSubPage::Base);
852- }
853- else if (subPage == BreadcrumbSubPage::Profile_Appearance)
854- {
855- profile.CurrentPage (ProfileSubPage::Appearance);
856- }
857- else if (subPage == BreadcrumbSubPage::Profile_Terminal)
858- {
859- profile.CurrentPage (ProfileSubPage::Terminal);
860- }
861- else if (subPage == BreadcrumbSubPage::Profile_Advanced)
879+ profile.CurrentPage (profileSubPage);
880+ if (needsForcedRefresh)
862881 {
863- profile.CurrentPage (ProfileSubPage::Advanced);
882+ // If we're already on the correct sub-page, the PropertyChanged event won't fire.
883+ // However, we still need to pass along the ElementToFocus, so we need to force a refresh.
884+ profileVMImpl->ForceRefreshCurrentPage ();
864885 }
865886 }
866887
0 commit comments