From 8b4e2e209997efdcfeeb65ac0eb43c92f4ae884f Mon Sep 17 00:00:00 2001 From: Kyle Lanmon Date: Thu, 14 Mar 2024 15:44:52 -0500 Subject: [PATCH] LibGUI: Call on_change when set text is called If there is an on_change callback, and we found at least one match, call the callback. --- Userland/Libraries/LibGUI/ComboBox.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/ComboBox.cpp b/Userland/Libraries/LibGUI/ComboBox.cpp index 1e6cc2a25f..27d1c7f5e5 100644 --- a/Userland/Libraries/LibGUI/ComboBox.cpp +++ b/Userland/Libraries/LibGUI/ComboBox.cpp @@ -292,7 +292,12 @@ ByteString ComboBox::text() const void ComboBox::set_text(ByteString const& text, AllowCallback allow_callback) { - m_editor->set_text(text, allow_callback); + m_editor->set_text(text); + if (!on_change || allow_callback == AllowCallback::No) + return; + auto matches = model()->matches(text.view(), GUI::Model::MatchesFlag::FirstMatchOnly); + if (!matches.is_empty()) + on_change(text, matches.first()); } void ComboBox::set_only_allow_values_from_model(bool b)