|
8 | 8 | #include "../TerminalSettingsModel/AllShortcutActions.h" |
9 | 9 |
|
10 | 10 | using namespace winrt::Windows::UI::Xaml; |
| 11 | +using namespace winrt::Windows::UI::Xaml::Controls; |
11 | 12 | using namespace winrt::Windows::UI::Xaml::Navigation; |
| 13 | +using namespace winrt::Windows::Foundation::Collections; |
12 | 14 |
|
13 | 15 | namespace winrt::Microsoft::Terminal::Settings::Editor::implementation |
14 | 16 | { |
@@ -49,5 +51,82 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation |
49 | 51 |
|
50 | 52 | CommandNameTextBox().Focus(FocusState::Programmatic); |
51 | 53 | }); |
| 54 | + |
| 55 | + // Initialize AutoSuggestBox with current action and store last valid action |
| 56 | + if (_ViewModel.ProposedShortcutActionName()) |
| 57 | + { |
| 58 | + const auto currentAction = winrt::unbox_value<winrt::hstring>(_ViewModel.ProposedShortcutActionName()); |
| 59 | + ShortcutActionBox().Text(currentAction); |
| 60 | + _lastValidAction = currentAction; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + void EditAction::ShortcutActionBox_GotFocus(const IInspectable& sender, const RoutedEventArgs&) |
| 65 | + { |
| 66 | + // Open the suggestions list with all available actions |
| 67 | + std::vector<winrt::hstring> allActions; |
| 68 | + for (const auto& action : _ViewModel.AvailableShortcutActions()) |
| 69 | + { |
| 70 | + allActions.push_back(action); |
| 71 | + } |
| 72 | + |
| 73 | + _filteredActions = winrt::single_threaded_observable_vector(std::move(allActions)); |
| 74 | + sender.as<AutoSuggestBox>().ItemsSource(_filteredActions); |
| 75 | + sender.as<AutoSuggestBox>().IsSuggestionListOpen(true); |
| 76 | + } |
| 77 | + |
| 78 | + void EditAction::ShortcutActionBox_TextChanged(const AutoSuggestBox& sender, const AutoSuggestBoxTextChangedEventArgs& args) |
| 79 | + { |
| 80 | + if (args.Reason() == AutoSuggestionBoxTextChangeReason::UserInput) |
| 81 | + { |
| 82 | + const auto searchText = sender.Text(); |
| 83 | + std::vector<winrt::hstring> filtered; |
| 84 | + |
| 85 | + for (const auto& action : _ViewModel.AvailableShortcutActions()) |
| 86 | + { |
| 87 | + if (til::contains_linguistic_insensitive(action, searchText)) |
| 88 | + { |
| 89 | + filtered.push_back(action); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + _filteredActions = winrt::single_threaded_observable_vector(std::move(filtered)); |
| 94 | + sender.ItemsSource(_filteredActions); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + void EditAction::ShortcutActionBox_SuggestionChosen(const AutoSuggestBox& sender, const AutoSuggestBoxSuggestionChosenEventArgs& args) |
| 99 | + { |
| 100 | + if (const auto selectedAction = args.SelectedItem().try_as<winrt::hstring>()) |
| 101 | + { |
| 102 | + sender.Text(*selectedAction); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + void EditAction::ShortcutActionBox_QuerySubmitted(const AutoSuggestBox& sender, const AutoSuggestBoxQuerySubmittedEventArgs& args) |
| 107 | + { |
| 108 | + const auto submittedText = args.QueryText(); |
| 109 | + |
| 110 | + // Validate that this is a valid shortcut action |
| 111 | + bool isValid = false; |
| 112 | + for (const auto& action : _ViewModel.AvailableShortcutActions()) |
| 113 | + { |
| 114 | + if (action == submittedText) |
| 115 | + { |
| 116 | + isValid = true; |
| 117 | + break; |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + if (isValid) |
| 122 | + { |
| 123 | + _ViewModel.ProposedShortcutActionName(winrt::box_value(submittedText)); |
| 124 | + _lastValidAction = submittedText; |
| 125 | + } |
| 126 | + else |
| 127 | + { |
| 128 | + // Revert to the last valid action |
| 129 | + sender.Text(_lastValidAction); |
| 130 | + } |
52 | 131 | } |
53 | 132 | } |
0 commit comments