Skip to content

Commit 0892689

Browse files
carlos-zamoraDHowett
authored andcommitted
[SUI] Improve accessibility to open json (microsoft#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. 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 microsoft#18770 Closes microsoft#12003 (cherry picked from commit a8a47b9) Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgZrDt4 Service-Version: 1.22
1 parent 246e1d5 commit 0892689

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
@@ -37,6 +37,7 @@ using namespace winrt::Windows::System;
3737
using namespace winrt::Windows::UI::Xaml::Controls;
3838
using namespace winrt::Windows::Foundation::Collections;
3939

40+
static const std::wstring_view openJsonTag{ L"OpenJson_Nav" };
4041
static const std::wstring_view launchTag{ L"Launch_Nav" };
4142
static const std::wstring_view interactionTag{ L"Interaction_Nav" };
4243
static const std::wstring_view renderingTag{ L"Rendering_Nav" };
@@ -288,6 +289,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
288289

289290
if (const auto navString = clickedItemContainer.Tag().try_as<hstring>())
290291
{
292+
if (*navString == openJsonTag)
293+
{
294+
const auto window = CoreWindow::GetForCurrentThread();
295+
const auto rAltState = window.GetKeyState(VirtualKey::RightMenu);
296+
const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu);
297+
const auto altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) ||
298+
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down);
299+
const auto target = altPressed ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile;
300+
OpenJson.raise(nullptr, target);
301+
return;
302+
}
291303
_Navigate(*navString, BreadcrumbSubPage::None);
292304
}
293305
else if (const auto profile = clickedItemContainer.Tag().try_as<Editor::ProfileViewModel>())
@@ -481,27 +493,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
481493
}
482494
}
483495

484-
void MainPage::OpenJsonTapped(const IInspectable& /*sender*/, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& /*args*/)
485-
{
486-
const auto window = CoreWindow::GetForCurrentThread();
487-
const auto rAltState = window.GetKeyState(VirtualKey::RightMenu);
488-
const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu);
489-
const auto altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) ||
490-
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down);
491-
492-
const auto target = altPressed ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile;
493-
OpenJson.raise(nullptr, target);
494-
}
495-
496-
void MainPage::OpenJsonKeyDown(const IInspectable& /*sender*/, const Windows::UI::Xaml::Input::KeyRoutedEventArgs& args)
497-
{
498-
if (args.Key() == VirtualKey::Enter || args.Key() == VirtualKey::Space)
499-
{
500-
const auto target = args.KeyStatus().IsMenuKeyDown ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile;
501-
OpenJson.raise(nullptr, target);
502-
}
503-
}
504-
505496
void MainPage::SaveButton_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*args*/)
506497
{
507498
_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
@@ -164,8 +164,8 @@
164164
<!-- The OpenJson item needs both Tapped and KeyDown handler -->
165165
<muxc:NavigationViewItem x:Name="OpenJsonNavItem"
166166
x:Uid="Nav_OpenJSON"
167-
KeyDown="OpenJsonKeyDown"
168-
Tapped="OpenJsonTapped">
167+
SelectsOnInvoked="False"
168+
Tag="OpenJson_Nav">
169169
<muxc:NavigationViewItem.Icon>
170170
<FontIcon Glyph="&#xE713;" />
171171
</muxc:NavigationViewItem.Icon>

0 commit comments

Comments
 (0)