Command Palette: announce various mode and state changes to UIA (#9582)

This commit introduces a few different announcements to the command
palette.

When you delete the `>`, it will announce that you have entered
"command-line mode". When you reintroduce the `>`, it will announce that
you are in "action search mode."

When you enter a nested command, it will announce that you are looking
at "more options for new tab..." or "more options for select color
scheme...".

When you search and find nothing, it will announce that there were no
matching commands (or tabs!)

Related to #7907.
This commit is contained in:
Dustin L. Howett 2021-03-23 06:24:27 -07:00 committed by GitHub
parent d972ea2c28
commit da3f02a6e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 1 deletions

View file

@ -530,6 +530,15 @@ namespace winrt::TerminalApp::implementation
// which will cause us to refresh the list of filterable commands.
_searchBox().Text(L"");
_searchBox().Focus(FocusState::Programmatic);
if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(_searchBox()) })
{
automationPeer.RaiseNotificationEvent(
Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::CurrentThenMostRecent,
fmt::format(std::wstring_view{ RS_(L"CommandPalette_NestedCommandAnnouncement") }, ParentCommandName()),
L"CommandPaletteNestingLevelChanged" /* unique name for this notification category */);
}
}
// Method Description:
@ -768,7 +777,19 @@ namespace winrt::TerminalApp::implementation
if (_currentMode == CommandPaletteMode::TabSearchMode || _currentMode == CommandPaletteMode::ActionMode)
{
_noMatchesText().Visibility(_filteredActions.Size() > 0 ? Visibility::Collapsed : Visibility::Visible);
const auto currentNeedleHasResults{ _filteredActions.Size() > 0 };
_noMatchesText().Visibility(currentNeedleHasResults ? Visibility::Collapsed : Visibility::Visible);
if (!currentNeedleHasResults)
{
if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(_searchBox()) })
{
automationPeer.RaiseNotificationEvent(
Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
NoMatchesText(), // NoMatchesText contains the right text for the current mode
L"CommandPaletteResultAnnouncement" /* unique name for this notification */);
}
}
}
else
{
@ -897,6 +918,9 @@ namespace winrt::TerminalApp::implementation
{
_currentMode = mode;
const auto currentlyVisible{ Visibility() == Visibility::Visible };
auto modeAnnouncementResourceKey{ USES_RESOURCE(L"CommandPaletteModeAnnouncement_ActionMode") };
ParsedCommandLineText(L"");
_searchBox().Text(L"");
_searchBox().Select(_searchBox().Text().size(), 0);
@ -912,6 +936,7 @@ namespace winrt::TerminalApp::implementation
NoMatchesText(RS_(L"TabSwitcher_NoMatchesText"));
ControlName(RS_(L"TabSwitcherControlName"));
PrefixCharacter(L"");
modeAnnouncementResourceKey = USES_RESOURCE(L"CommandPaletteModeAnnouncement_TabSearchSwitchMode");
break;
}
case CommandPaletteMode::CommandlineMode:
@ -919,6 +944,7 @@ namespace winrt::TerminalApp::implementation
NoMatchesText(L"");
ControlName(RS_(L"CommandPaletteControlName"));
PrefixCharacter(L"");
modeAnnouncementResourceKey = USES_RESOURCE(L"CommandPaletteModeAnnouncement_CommandlineMode");
break;
case CommandPaletteMode::ActionMode:
default:
@ -926,9 +952,23 @@ namespace winrt::TerminalApp::implementation
NoMatchesText(RS_(L"CommandPalette_NoMatchesText/Text"));
ControlName(RS_(L"CommandPaletteControlName"));
PrefixCharacter(L">");
// modeAnnouncementResourceKey is already set to _ActionMode
// We did this above to deduce the type (and make it easier on ourselves later).
break;
}
if (currentlyVisible)
{
if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(_searchBox()) })
{
automationPeer.RaiseNotificationEvent(
Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::CurrentThenMostRecent,
GetLibraryResourceString(modeAnnouncementResourceKey),
L"CommandPaletteModeSwitch" /* unique ID for this notification */);
}
}
// The smooth remove/add animations that happen during
// UpdateFilteredActions don't work very well when switching between
// modes because of the sheer amount of remove/adds. So, let's just

View file

@ -459,6 +459,22 @@
<data name="CommandPalette_NoMatchesText.Text" xml:space="preserve">
<value>No matching commands</value>
</data>
<data name="CommandPaletteModeAnnouncement_ActionMode" xml:space="preserve">
<value>Action search mode</value>
<comment>This text will be read aloud using assistive technologies when the command palette switches into action (command search) mode.</comment>
</data>
<data name="CommandPaletteModeAnnouncement_TabSearchSwitchMode" xml:space="preserve">
<value>Tab title mode</value>
<comment>This text will be read aloud using assistive technologies when the command palette switches into a mode that filters tab names.</comment>
</data>
<data name="CommandPaletteModeAnnouncement_CommandlineMode" xml:space="preserve">
<value>Command-line mode</value>
<comment>This text will be read aloud using assistive technologies when the command palette switches into the raw commandline parsing mode.</comment>
</data>
<data name="CommandPalette_NestedCommandAnnouncement" xml:space="preserve">
<value>More options for "{}"</value>
<comment>This text will be read aloud using assistive technologies when the user selects a command that has additional options. The {} will be expanded to the name of the command containing more options.</comment>
</data>
<data name="CommandPalette_ParsedCommandLine" xml:space="preserve">
<value>Executing command line will invoke the following commands:</value>
<comment>Will be followed by a list of strings describing parsed commands</comment>

View file

@ -46,6 +46,7 @@
#include "winrt/Windows.UI.Xaml.Markup.h"
#include "winrt/Windows.UI.Xaml.Documents.h"
#include "winrt/Windows.UI.Xaml.Automation.h"
#include "winrt/Windows.UI.Xaml.Automation.Peers.h"
#include "winrt/Windows.UI.ViewManagement.h"
#include <winrt/Windows.ApplicationModel.h>
#include <winrt/Windows.ApplicationModel.DataTransfer.h>