mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-04 01:04:40 +00:00
add search for actions box
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
#include "../TerminalSettingsModel/AllShortcutActions.h"
|
||||
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
using namespace winrt::Windows::UI::Xaml::Controls;
|
||||
using namespace winrt::Windows::UI::Xaml::Navigation;
|
||||
using namespace winrt::Windows::Foundation::Collections;
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
{
|
||||
@@ -49,5 +51,82 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
|
||||
CommandNameTextBox().Focus(FocusState::Programmatic);
|
||||
});
|
||||
|
||||
// Initialize AutoSuggestBox with current action and store last valid action
|
||||
if (_ViewModel.ProposedShortcutActionName())
|
||||
{
|
||||
const auto currentAction = winrt::unbox_value<winrt::hstring>(_ViewModel.ProposedShortcutActionName());
|
||||
ShortcutActionBox().Text(currentAction);
|
||||
_lastValidAction = currentAction;
|
||||
}
|
||||
}
|
||||
|
||||
void EditAction::ShortcutActionBox_GotFocus(const IInspectable& sender, const RoutedEventArgs&)
|
||||
{
|
||||
// Open the suggestions list with all available actions
|
||||
std::vector<winrt::hstring> allActions;
|
||||
for (const auto& action : _ViewModel.AvailableShortcutActions())
|
||||
{
|
||||
allActions.push_back(action);
|
||||
}
|
||||
|
||||
_filteredActions = winrt::single_threaded_observable_vector(std::move(allActions));
|
||||
sender.as<AutoSuggestBox>().ItemsSource(_filteredActions);
|
||||
sender.as<AutoSuggestBox>().IsSuggestionListOpen(true);
|
||||
}
|
||||
|
||||
void EditAction::ShortcutActionBox_TextChanged(const AutoSuggestBox& sender, const AutoSuggestBoxTextChangedEventArgs& args)
|
||||
{
|
||||
if (args.Reason() == AutoSuggestionBoxTextChangeReason::UserInput)
|
||||
{
|
||||
const auto searchText = sender.Text();
|
||||
std::vector<winrt::hstring> filtered;
|
||||
|
||||
for (const auto& action : _ViewModel.AvailableShortcutActions())
|
||||
{
|
||||
if (til::contains_linguistic_insensitive(action, searchText))
|
||||
{
|
||||
filtered.push_back(action);
|
||||
}
|
||||
}
|
||||
|
||||
_filteredActions = winrt::single_threaded_observable_vector(std::move(filtered));
|
||||
sender.ItemsSource(_filteredActions);
|
||||
}
|
||||
}
|
||||
|
||||
void EditAction::ShortcutActionBox_SuggestionChosen(const AutoSuggestBox& sender, const AutoSuggestBoxSuggestionChosenEventArgs& args)
|
||||
{
|
||||
if (const auto selectedAction = args.SelectedItem().try_as<winrt::hstring>())
|
||||
{
|
||||
sender.Text(*selectedAction);
|
||||
}
|
||||
}
|
||||
|
||||
void EditAction::ShortcutActionBox_QuerySubmitted(const AutoSuggestBox& sender, const AutoSuggestBoxQuerySubmittedEventArgs& args)
|
||||
{
|
||||
const auto submittedText = args.QueryText();
|
||||
|
||||
// Validate that this is a valid shortcut action
|
||||
bool isValid = false;
|
||||
for (const auto& action : _ViewModel.AvailableShortcutActions())
|
||||
{
|
||||
if (action == submittedText)
|
||||
{
|
||||
isValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
_ViewModel.ProposedShortcutActionName(winrt::box_value(submittedText));
|
||||
_lastValidAction = submittedText;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Revert to the last valid action
|
||||
sender.Text(_lastValidAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
|
||||
WINRT_OBSERVABLE_PROPERTY(Editor::CommandViewModel, ViewModel, PropertyChanged.raise, nullptr);
|
||||
|
||||
void ShortcutActionBox_GotFocus(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& args);
|
||||
void ShortcutActionBox_TextChanged(const winrt::Windows::UI::Xaml::Controls::AutoSuggestBox& sender, const winrt::Windows::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs& args);
|
||||
void ShortcutActionBox_SuggestionChosen(const winrt::Windows::UI::Xaml::Controls::AutoSuggestBox& sender, const winrt::Windows::UI::Xaml::Controls::AutoSuggestBoxSuggestionChosenEventArgs& args);
|
||||
void ShortcutActionBox_QuerySubmitted(const winrt::Windows::UI::Xaml::Controls::AutoSuggestBox& sender, const winrt::Windows::UI::Xaml::Controls::AutoSuggestBoxQuerySubmittedEventArgs& args);
|
||||
|
||||
private:
|
||||
friend struct EditActionT<EditAction>; // for Xaml to bind events
|
||||
winrt::Windows::UI::Xaml::FrameworkElement::LayoutUpdated_revoker _layoutUpdatedRevoker;
|
||||
Editor::CommandViewModel::PropagateWindowRootRequested_revoker _propagateWindowRootRevoker;
|
||||
Editor::CommandViewModel::FocusContainer_revoker _focusContainerRevoker;
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> _filteredActions{ nullptr };
|
||||
winrt::hstring _lastValidAction;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -678,12 +678,15 @@
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
VerticalAlignment="Center" />
|
||||
<ComboBox Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="{x:Bind ViewModel.ShortcutActionComboBoxAutomationPropName}"
|
||||
ItemsSource="{x:Bind ViewModel.AvailableShortcutActions, Mode=OneWay}"
|
||||
SelectedItem="{x:Bind ViewModel.ProposedShortcutActionName, Mode=TwoWay}" />
|
||||
<AutoSuggestBox x:Name="ShortcutActionBox"
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="{x:Bind ViewModel.ShortcutActionComboBoxAutomationPropName}"
|
||||
GotFocus="ShortcutActionBox_GotFocus"
|
||||
QuerySubmitted="ShortcutActionBox_QuerySubmitted"
|
||||
SuggestionChosen="ShortcutActionBox_SuggestionChosen"
|
||||
TextChanged="ShortcutActionBox_TextChanged" />
|
||||
<TextBlock x:Uid="Actions_Arguments"
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
|
||||
Reference in New Issue
Block a user