Skip to content

Commit 7a05501

Browse files
authored
A first couple Suggestion UI nits (#15848)
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.
1 parent b024efb commit 7a05501

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

src/cascadia/TerminalApp/Resources/en-US/Resources.resw

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,26 @@
590590
<value>Enter a wt commandline to run</value>
591591
<comment>{Locked="wt"} </comment>
592592
</data>
593+
<data name="SuggestionsControl_NestedCommandAnnouncement" xml:space="preserve">
594+
<value>More options for "{}"</value>
595+
<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>
596+
</data>
597+
<data name="SuggestionsControl_SearchBox.PlaceholderText" xml:space="preserve">
598+
<value>Type a command name...</value>
599+
</data>
600+
<data name="SuggestionsControl_NoMatchesText.Text" xml:space="preserve">
601+
<value>No matching commands</value>
602+
</data>
603+
<data name="SuggestionsControlName" xml:space="preserve">
604+
<value>Suggestions menu</value>
605+
</data>
606+
<data name="SuggestionsControl_MoreOptions.[using:Windows.UI.Xaml.Automation]AutomationProperties.HelpText" xml:space="preserve">
607+
<value>More options</value>
608+
</data>
609+
<data name="SuggestionsControl_MatchesAvailable" xml:space="preserve">
610+
<value>Suggestions found: {0}</value>
611+
<comment>{0} will be replaced with a number.</comment>
612+
</data>
593613
<data name="CrimsonColorButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
594614
<value>Crimson</value>
595615
</data>

src/cascadia/TerminalApp/SuggestionsControl.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ namespace winrt::TerminalApp::implementation
584584
automationPeer.RaiseNotificationEvent(
585585
Automation::Peers::AutomationNotificationKind::ActionCompleted,
586586
Automation::Peers::AutomationNotificationProcessing::CurrentThenMostRecent,
587-
fmt::format(std::wstring_view{ RS_(L"CommandPalette_NestedCommandAnnouncement") }, ParentCommandName()),
587+
fmt::format(std::wstring_view{ RS_(L"SuggestionsControl_NestedCommandAnnouncement") }, ParentCommandName()),
588588
L"SuggestionsControlNestingLevelChanged" /* unique name for this notification category */);
589589
}
590590
}
@@ -725,10 +725,12 @@ namespace winrt::TerminalApp::implementation
725725
// here will ensure that we can check this case appropriately.
726726
_lastFilterTextWasEmpty = _searchBox().Text().empty();
727727

728+
const auto lastSelectedIndex = _filteredActionsView().SelectedIndex();
729+
728730
_updateFilteredActions();
729731

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

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

782784
void SuggestionsControl::_switchToMode()
783785
{
784-
const auto currentlyVisible{ Visibility() == Visibility::Visible };
785-
786-
auto modeAnnouncementResourceKey{ USES_RESOURCE(L"CommandPaletteModeAnnouncement_ActionMode") };
787786
ParsedCommandLineText(L"");
788787
_searchBox().Text(L"");
789788
_searchBox().Select(_searchBox().Text().size(), 0);
@@ -795,23 +794,9 @@ namespace winrt::TerminalApp::implementation
795794
// guarantees that the correct text is shown for the mode
796795
// whenever _switchToMode is called.
797796

798-
SearchBoxPlaceholderText(RS_(L"CommandPalette_SearchBox/PlaceholderText"));
799-
NoMatchesText(RS_(L"CommandPalette_NoMatchesText/Text"));
800-
ControlName(RS_(L"CommandPaletteControlName"));
801-
// modeAnnouncementResourceKey is already set to _ActionMode
802-
// We did this above to deduce the type (and make it easier on ourselves later).
803-
804-
if (currentlyVisible)
805-
{
806-
if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(_searchBox()) })
807-
{
808-
automationPeer.RaiseNotificationEvent(
809-
Automation::Peers::AutomationNotificationKind::ActionCompleted,
810-
Automation::Peers::AutomationNotificationProcessing::CurrentThenMostRecent,
811-
GetLibraryResourceString(modeAnnouncementResourceKey),
812-
L"SuggestionsControlModeSwitch" /* unique ID for this notification */);
813-
}
814-
}
797+
SearchBoxPlaceholderText(RS_(L"SuggestionsControl_SearchBox/PlaceholderText"));
798+
NoMatchesText(RS_(L"SuggestionsControl_NoMatchesText/Text"));
799+
ControlName(RS_(L"SuggestionsControlName"));
815800

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

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

@@ -1104,6 +1089,19 @@ namespace winrt::TerminalApp::implementation
11041089
Margin(newMargin);
11051090

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

11091107
}

0 commit comments

Comments
 (0)