Skip to content

Commit

Permalink
[a11y] Make CommandPalette announce selected item
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Jul 16, 2022
1 parent 67662e1 commit d5d1e88
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TerminalApp::FilteredCommand>())
{
if (const auto paletteItem = filteredCmd.Item().try_as<TerminalApp::PaletteItem>())
{
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.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/CommandPalette.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@
IsItemClickEnabled="True"
ItemClick="_listItemClicked"
ItemsSource="{x:Bind FilteredActions}"
SelectionMode="Single" />
SelectionMode="Single"
SelectionChanged="_listItemSelectionChanged"/>

</Grid>

Expand Down

0 comments on commit d5d1e88

Please sign in to comment.