From 7e10f76021cc4664105b97064bda01f1a51c7c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20M=C3=BCck?= Date: Sun, 22 Oct 2023 19:48:20 +0200 Subject: [PATCH] LibGUI: Don't update ComboBox text when model index is invalid Without ENABLE_TIME_ZONE_DATA the user is able to update the time zone selection when using "on_mousewheel" or "on_{up,down}_pressed" even though UTC is supposed to be the only option. Due to an invalid model index, the selection is set to "[null]". Prior to this patch, the ComboBox text in "selection_updated" is set at each call. --- Userland/Libraries/LibGUI/ComboBox.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGUI/ComboBox.cpp b/Userland/Libraries/LibGUI/ComboBox.cpp index 3e16a63a15..fee48a11ee 100644 --- a/Userland/Libraries/LibGUI/ComboBox.cpp +++ b/Userland/Libraries/LibGUI/ComboBox.cpp @@ -177,12 +177,13 @@ void ComboBox::navigate_relative(int delta) void ComboBox::selection_updated(ModelIndex const& index) { - if (index.is_valid()) + if (index.is_valid()) { m_selected_index = index; - else + auto new_value = index.data().to_deprecated_string(); + m_editor->set_text(new_value); + } else { m_selected_index.clear(); - auto new_value = index.data().to_deprecated_string(); - m_editor->set_text(new_value); + } if (!m_only_allow_values_from_model) m_editor->select_all(); }