Skip to content

Commit

Permalink
A first couple Suggestion UI nits (#15848)
Browse files Browse the repository at this point in the history
Closes the active checkboxes in #15845. I'll leave that open till we get
to the endgame, I'm sure more will show up.

Closes:

- [x] Accessibility tags all have `CommandPalette_` strings 🤣 
- [x] useCommandline should leave the cursor at the _end_ of the input,
not at the start
- [x] useCommandline, when bottom-up, should leave the _last_ list item
selected, not the first.
- [x] ^ Probably applies to any changes to the filter text when bottom
up.
  • Loading branch information
zadjii-msft authored Aug 24, 2023
1 parent b024efb commit 7a05501
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
20 changes: 20 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,26 @@
<value>Enter a wt commandline to run</value>
<comment>{Locked="wt"} </comment>
</data>
<data name="SuggestionsControl_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="SuggestionsControl_SearchBox.PlaceholderText" xml:space="preserve">
<value>Type a command name...</value>
</data>
<data name="SuggestionsControl_NoMatchesText.Text" xml:space="preserve">
<value>No matching commands</value>
</data>
<data name="SuggestionsControlName" xml:space="preserve">
<value>Suggestions menu</value>
</data>
<data name="SuggestionsControl_MoreOptions.[using:Windows.UI.Xaml.Automation]AutomationProperties.HelpText" xml:space="preserve">
<value>More options</value>
</data>
<data name="SuggestionsControl_MatchesAvailable" xml:space="preserve">
<value>Suggestions found: {0}</value>
<comment>{0} will be replaced with a number.</comment>
</data>
<data name="CrimsonColorButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Crimson</value>
</data>
Expand Down
46 changes: 22 additions & 24 deletions src/cascadia/TerminalApp/SuggestionsControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ namespace winrt::TerminalApp::implementation
automationPeer.RaiseNotificationEvent(
Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::CurrentThenMostRecent,
fmt::format(std::wstring_view{ RS_(L"CommandPalette_NestedCommandAnnouncement") }, ParentCommandName()),
fmt::format(std::wstring_view{ RS_(L"SuggestionsControl_NestedCommandAnnouncement") }, ParentCommandName()),
L"SuggestionsControlNestingLevelChanged" /* unique name for this notification category */);
}
}
Expand Down Expand Up @@ -725,10 +725,12 @@ namespace winrt::TerminalApp::implementation
// here will ensure that we can check this case appropriately.
_lastFilterTextWasEmpty = _searchBox().Text().empty();

const auto lastSelectedIndex = _filteredActionsView().SelectedIndex();

_updateFilteredActions();

// In the command line mode we want the user to explicitly select the command
_filteredActionsView().SelectedIndex(0);
_filteredActionsView().SelectedIndex(std::min<int32_t>(lastSelectedIndex, _filteredActionsView().Items().Size() - 1));

const auto currentNeedleHasResults{ _filteredActions.Size() > 0 };
_noMatchesText().Visibility(currentNeedleHasResults ? Visibility::Collapsed : Visibility::Visible);
Expand All @@ -738,7 +740,7 @@ namespace winrt::TerminalApp::implementation
Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
currentNeedleHasResults ?
winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"CommandPalette_MatchesAvailable") }, _filteredActions.Size()) } :
winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"SuggestionsControl_MatchesAvailable") }, _filteredActions.Size()) } :
NoMatchesText(), // what to announce if results were found
L"SuggestionsControlResultAnnouncement" /* unique name for this group of notifications */);
}
Expand Down Expand Up @@ -781,9 +783,6 @@ namespace winrt::TerminalApp::implementation

void SuggestionsControl::_switchToMode()
{
const auto currentlyVisible{ Visibility() == Visibility::Visible };

auto modeAnnouncementResourceKey{ USES_RESOURCE(L"CommandPaletteModeAnnouncement_ActionMode") };
ParsedCommandLineText(L"");
_searchBox().Text(L"");
_searchBox().Select(_searchBox().Text().size(), 0);
Expand All @@ -795,23 +794,9 @@ namespace winrt::TerminalApp::implementation
// guarantees that the correct text is shown for the mode
// whenever _switchToMode is called.

SearchBoxPlaceholderText(RS_(L"CommandPalette_SearchBox/PlaceholderText"));
NoMatchesText(RS_(L"CommandPalette_NoMatchesText/Text"));
ControlName(RS_(L"CommandPaletteControlName"));
// modeAnnouncementResourceKey is already set to _ActionMode
// We did this above to deduce the type (and make it easier on ourselves later).

if (currentlyVisible)
{
if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(_searchBox()) })
{
automationPeer.RaiseNotificationEvent(
Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::CurrentThenMostRecent,
GetLibraryResourceString(modeAnnouncementResourceKey),
L"SuggestionsControlModeSwitch" /* unique ID for this notification */);
}
}
SearchBoxPlaceholderText(RS_(L"SuggestionsControl_SearchBox/PlaceholderText"));
NoMatchesText(RS_(L"SuggestionsControl_NoMatchesText/Text"));
ControlName(RS_(L"SuggestionsControlName"));

// The smooth remove/add animations that happen during
// UpdateFilteredActions don't work very well when switching between
Expand Down Expand Up @@ -1004,7 +989,7 @@ namespace winrt::TerminalApp::implementation

if (dataTemplate == _itemTemplateSelector.NestedItemTemplate())
{
const auto helpText = winrt::box_value(RS_(L"CommandPalette_MoreOptions/[using:Windows.UI.Xaml.Automation]AutomationProperties/HelpText"));
const auto helpText = winrt::box_value(RS_(L"SuggestionsControl_MoreOptions/[using:Windows.UI.Xaml.Automation]AutomationProperties/HelpText"));
listViewItem.SetValue(Automation::AutomationProperties::HelpTextProperty(), helpText);
}

Expand Down Expand Up @@ -1104,6 +1089,19 @@ namespace winrt::TerminalApp::implementation
Margin(newMargin);

_searchBox().Text(filter);

// If we're in bottom-up mode, make sure to re-select the _last_ item in
// the list, so that it's like we're starting with the most recent one
// selected.
if (_direction == TerminalApp::SuggestionsDirection::BottomUp)
{
const auto last = _filteredActionsView().Items().Size() - 1;
_filteredActionsView().SelectedIndex(last);
}
// Move the cursor to the very last position, so it starts immediately
// after the text. This is apparently done by starting a 0-wide
// selection starting at the end of the string.
_searchBox().Select(filter.size(), 0);
}

}

0 comments on commit 7a05501

Please sign in to comment.