Skip to content

Commit e8a883f

Browse files
carlos-zamoraDHowett
authored andcommitted
[SUI] Improve accessibility to open json (#18828)
The "open JSON" button in the settings UI wasn't working when invoked via accessibility tools (specifically Narrator in scan mode and Voice Access). For some reason, in those scenarios, neither the `Tapped` or `KeyDown` event were hit! This PR adds the logic to open the json file via the `ItemInvoked` event instead. The `Tapped` and `KeyDown` handlers were removed to prevent a redundant `OpenJson` event being raised. Additionally, `SelectsOnInvoked` was set to `False` on the "open JSON" nav item. This prevents the selection pill from moving to the nav item, which feels more correct. ## Validation Steps Performed The following scenarios are confirmed to open the JSON ✅ Mouse click ✅ Keyboard (Spacebar and Enter) ✅ Voice Access ✅ Narrator in scan mode For all of these (except Voice Access), I've confirmed that holding the Alt button while invoking the JSON button opens defaults.json. Closes #18770 Closes #12003 (cherry picked from commit a8a47b9) Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgZrZKs PVTI_lADOAF3p4s4AxadtzgZrDtw Service-Version: 1.23
1 parent 42a0b13 commit e8a883f

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

src/cascadia/TerminalSettingsEditor/MainPage.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ using namespace winrt::Windows::System;
3838
using namespace winrt::Windows::UI::Xaml::Controls;
3939
using namespace winrt::Windows::Foundation::Collections;
4040

41+
static const std::wstring_view openJsonTag{ L"OpenJson_Nav" };
4142
static const std::wstring_view launchTag{ L"Launch_Nav" };
4243
static const std::wstring_view interactionTag{ L"Interaction_Nav" };
4344
static const std::wstring_view renderingTag{ L"Rendering_Nav" };
@@ -324,6 +325,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
324325

325326
if (const auto navString = clickedItemContainer.Tag().try_as<hstring>())
326327
{
328+
if (*navString == openJsonTag)
329+
{
330+
const auto window = CoreWindow::GetForCurrentThread();
331+
const auto rAltState = window.GetKeyState(VirtualKey::RightMenu);
332+
const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu);
333+
const auto altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) ||
334+
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down);
335+
const auto target = altPressed ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile;
336+
OpenJson.raise(nullptr, target);
337+
return;
338+
}
327339
_Navigate(*navString, BreadcrumbSubPage::None);
328340
}
329341
else if (const auto profile = clickedItemContainer.Tag().try_as<Editor::ProfileViewModel>())
@@ -575,27 +587,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
575587
}
576588
}
577589

578-
void MainPage::OpenJsonTapped(const IInspectable& /*sender*/, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& /*args*/)
579-
{
580-
const auto window = CoreWindow::GetForCurrentThread();
581-
const auto rAltState = window.GetKeyState(VirtualKey::RightMenu);
582-
const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu);
583-
const auto altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) ||
584-
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down);
585-
586-
const auto target = altPressed ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile;
587-
OpenJson.raise(nullptr, target);
588-
}
589-
590-
void MainPage::OpenJsonKeyDown(const IInspectable& /*sender*/, const Windows::UI::Xaml::Input::KeyRoutedEventArgs& args)
591-
{
592-
if (args.Key() == VirtualKey::Enter || args.Key() == VirtualKey::Space)
593-
{
594-
const auto target = args.KeyStatus().IsMenuKeyDown ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile;
595-
OpenJson.raise(nullptr, target);
596-
}
597-
}
598-
599590
void MainPage::SaveButton_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*args*/)
600591
{
601592
_settingsClone.LogSettingChanges(false);

src/cascadia/TerminalSettingsEditor/MainPage.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
3030

3131
void UpdateSettings(const Model::CascadiaSettings& settings);
3232

33-
void OpenJsonKeyDown(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::KeyRoutedEventArgs& args);
34-
void OpenJsonTapped(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& args);
3533
void SettingsNav_Loaded(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);
3634
void SettingsNav_ItemInvoked(const Microsoft::UI::Xaml::Controls::NavigationView& sender, const Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs& args);
3735
void SaveButton_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);

src/cascadia/TerminalSettingsEditor/MainPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@
171171
<!-- The OpenJson item needs both Tapped and KeyDown handler -->
172172
<muxc:NavigationViewItem x:Name="OpenJsonNavItem"
173173
x:Uid="Nav_OpenJSON"
174-
KeyDown="OpenJsonKeyDown"
175-
Tapped="OpenJsonTapped">
174+
SelectsOnInvoked="False"
175+
Tag="OpenJson_Nav">
176176
<muxc:NavigationViewItem.Icon>
177177
<FontIcon Glyph="&#xE713;" />
178178
</muxc:NavigationViewItem.Icon>

0 commit comments

Comments
 (0)