diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 6aa2be583a2..d05056b2543 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -530,6 +530,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 ebf32d3594b..b22070023d2 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 ce1581b3605..476cf029b30 100644 --- a/src/cascadia/TerminalApp/CommandPalette.xaml +++ b/src/cascadia/TerminalApp/CommandPalette.xaml @@ -402,6 +402,7 @@ IsItemClickEnabled="True" ItemClick="_listItemClicked" ItemsSource="{x:Bind FilteredActions}" + SelectionChanged="_listItemSelectionChanged" SelectionMode="Single" />