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.
This commit is contained in:
Adrian Mück 2023-10-22 19:48:20 +02:00 committed by Tim Flynn
parent 3b733ff7bc
commit 7e10f76021
Notes: sideshowbarker 2024-07-19 16:50:03 +09:00

View file

@ -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();
}