From bcac9993cb84a7736e3db00c9d7262defd0f85a1 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 26 Sep 2024 17:06:01 +0200 Subject: [PATCH] Stop updating AutoSuggestBox on selection (#17961) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `AutoSuggestBox` has a `SuggestionChosen` event and any reasonable person would assume that this means one of the items was chosen. But with WinUI it's raised whenever a suggestion is merely highlighted. `QuerySubmitted` is the right event instead. Clearly that naming is a lot better than `SuggestionChosen`, since the property to get the chosen item is called `ChosenSuggestion`. WinUI, like the unrelenting wilderness of a world indifferent to human suffering, stands as a testament to the futility of human aspiration. Closes #17916 ## Validation Steps Performed * Type "Casc" * Move up/down with the arrow keys * Neither the filtered list nor the text updates ✅ * Press Enter on an item * Text updates ✅ --- src/cascadia/TerminalSettingsEditor/Appearances.cpp | 4 ++-- src/cascadia/TerminalSettingsEditor/Appearances.h | 2 +- src/cascadia/TerminalSettingsEditor/Appearances.xaml | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index 3fcbfb58a2c..bd299e196ad 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -1030,9 +1030,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } - void Appearances::FontFaceBox_SuggestionChosen(const AutoSuggestBox& sender, const AutoSuggestBoxSuggestionChosenEventArgs& args) + void Appearances::FontFaceBox_QuerySubmitted(const AutoSuggestBox& sender, const AutoSuggestBoxQuerySubmittedEventArgs& args) { - const auto font = unbox_value(args.SelectedItem()); + const auto font = unbox_value(args.ChosenSuggestion()); const auto fontName = font.Name(); auto fontSpec = sender.Text(); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.h b/src/cascadia/TerminalSettingsEditor/Appearances.h index 27a58073a8f..97773d8e9fa 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.h +++ b/src/cascadia/TerminalSettingsEditor/Appearances.h @@ -179,7 +179,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void FontFaceBox_GotFocus(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& e); void FontFaceBox_LostFocus(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& e); - void FontFaceBox_SuggestionChosen(const winrt::Windows::UI::Xaml::Controls::AutoSuggestBox&, const winrt::Windows::UI::Xaml::Controls::AutoSuggestBoxSuggestionChosenEventArgs&); + void FontFaceBox_QuerySubmitted(const winrt::Windows::UI::Xaml::Controls::AutoSuggestBox&, const winrt::Windows::UI::Xaml::Controls::AutoSuggestBoxQuerySubmittedEventArgs&); void FontFaceBox_TextChanged(const winrt::Windows::UI::Xaml::Controls::AutoSuggestBox&, const winrt::Windows::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs&); void DeleteFontKeyValuePair_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& e); safe_void_coroutine BackgroundImage_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& e); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index a3f643c53c3..080f751b15e 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -214,10 +214,11 @@ ItemTemplate="{StaticResource FontFaceComboBoxItemTemplate}" ItemsSource="{x:Bind FilteredFontList, Mode=OneWay}" LostFocus="FontFaceBox_LostFocus" - SuggestionChosen="FontFaceBox_SuggestionChosen" + QuerySubmitted="FontFaceBox_QuerySubmitted" Text="{x:Bind Appearance.FontFace, Mode=OneWay}" TextBoxStyle="{StaticResource TextBoxSettingStyle}" - TextChanged="FontFaceBox_TextChanged" /> + TextChanged="FontFaceBox_TextChanged" + UpdateTextOnSelect="False" />