From d5d1e886aaf44f62313e23dc92939ed65edc8b2e Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Fri, 15 Jul 2022 17:25:33 -0700 Subject: [PATCH] [a11y] Make CommandPalette announce selected item --- src/cascadia/TerminalApp/CommandPalette.cpp | 28 ++++++++++++++++++++ src/cascadia/TerminalApp/CommandPalette.h | 2 ++ src/cascadia/TerminalApp/CommandPalette.xaml | 3 ++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 1bc72516d665..59d9e2ea7439 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -524,6 +524,34 @@ namespace winrt::TerminalApp::implementation } } + void CommandPalette::_listItemSelectionChanged(const Windows::Foundation::IInspectable& /*sender*/, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& e) + { + // We don't care about... + // - CommandlineMode: it doesn't have any selectable items in the list view + // - TabSwitchMode: focus and selected item are in sync + if (_currentMode == CommandPaletteMode::ActionMode || _currentMode == CommandPaletteMode::TabSearchMode) + { + if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(_searchBox()) }) + { + if (const auto selectedList = e.AddedItems(); selectedList.Size() > 0) + { + const auto selectedCommand = selectedList.GetAt(0); + if (const auto filteredCmd = selectedCommand.try_as()) + { + if (const auto paletteItem = filteredCmd.Item().try_as()) + { + automationPeer.RaiseNotificationEvent( + Automation::Peers::AutomationNotificationKind::ItemAdded, + Automation::Peers::AutomationNotificationProcessing::MostRecent, + paletteItem.Name() + L" " + paletteItem.KeyChordText(), + L"CommandPaletteSelectedItemChanged" /* unique name for this notification category */); + } + } + } + } + } + } + // Method Description: // This event is called when the user clicks on an ChevronLeft button right // next to the ParentCommandName (e.g. New Tab...) above the subcommands list. diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index ebf32d3594bf..b22070023d2e 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -92,6 +92,8 @@ namespace winrt::TerminalApp::implementation void _listItemClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Controls::ItemClickEventArgs& e); + void _listItemSelectionChanged(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& e); + void _moveBackButtonClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs&); void _updateFilteredActions(); diff --git a/src/cascadia/TerminalApp/CommandPalette.xaml b/src/cascadia/TerminalApp/CommandPalette.xaml index ce1581b36050..c6d3a2b4ab97 100644 --- a/src/cascadia/TerminalApp/CommandPalette.xaml +++ b/src/cascadia/TerminalApp/CommandPalette.xaml @@ -402,7 +402,8 @@ IsItemClickEnabled="True" ItemClick="_listItemClicked" ItemsSource="{x:Bind FilteredActions}" - SelectionMode="Single" /> + SelectionMode="Single" + SelectionChanged="_listItemSelectionChanged"/>