Skip to content

Commit 83aa9fd

Browse files
committed
profiles: fix BringIntoView (partially)
1 parent 8c99200 commit 83aa9fd

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

src/cascadia/TerminalSettingsEditor/MainPage.cpp

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/cascadia/TerminalSettingsEditor/ProfileViewModel.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
5959
void DeleteProfile();
6060

6161
void SetupAppearances(Windows::Foundation::Collections::IObservableVector<Editor::ColorSchemeViewModel> schemesList);
62+
void ForceRefreshCurrentPage()
63+
{
64+
// Used to trigger the PropertyChanged handler in MainPage.cpp
65+
// This forces the page to refresh
66+
_NotifyChanges(L"CurrentPage");
67+
}
6268

6369
// bell style bits
6470
hstring BellStylePreview() const;
@@ -177,6 +183,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
177183

178184
WINRT_PROPERTY(bool, IsBaseLayer, false);
179185
WINRT_PROPERTY(bool, FocusDeleteButton, false);
186+
WINRT_PROPERTY(hstring, ElementToFocus);
180187
WINRT_PROPERTY(Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable>, IconTypes);
181188
GETSET_BINDABLE_ENUM_SETTING(AntiAliasingMode, Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode);
182189
GETSET_BINDABLE_ENUM_SETTING(CloseOnExitMode, Microsoft::Terminal::Settings::Model::CloseOnExitMode, CloseOnExit);

src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
CornerRadius="{StaticResource ControlCornerRadius}" />
7676
</Border>
7777

78-
<local:Appearances Appearance="{x:Bind Profile.DefaultAppearance, Mode=OneWay}"
78+
<local:Appearances x:Name="DefaultAppearanceView"
79+
Appearance="{x:Bind Profile.DefaultAppearance, Mode=OneWay}"
7980
SourceProfile="{x:Bind Profile, Mode=OneWay}"
8081
WindowRoot="{x:Bind WindowRoot, Mode=OneTime}" />
8182

@@ -251,7 +252,8 @@
251252
</StackPanel>
252253

253254
<!-- Unfocused Appearance -->
254-
<local:Appearances Appearance="{x:Bind Profile.UnfocusedAppearance, Mode=OneWay}"
255+
<local:Appearances x:Name="UnfocusedAppearanceView"
256+
Appearance="{x:Bind Profile.UnfocusedAppearance, Mode=OneWay}"
255257
SourceProfile="{x:Bind Profile, Mode=OneWay}"
256258
Visibility="{x:Bind Profile.ShowUnfocusedAppearance, Mode=OneWay}"
257259
WindowRoot="{x:Bind WindowRoot, Mode=OneTime}" />

0 commit comments

Comments
 (0)