This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 2ef6161b043ea6a7707b275c4628bd23d4005efd
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 10 18:12:24 2026 -0600

    elementary: select_model: a pick after leaving multi keeps its row
    
    Leaving multiple selection for single queues the unselects of every row
    but the kept one. Picking, in the same turn, a row that was still
    selected was treated as a select that changes nothing, so it did not
    become the selected one, and the queued unselect then took it away.
    
    Such a pick now goes through the single-mode path (it replaces the
    selected row), and the queued unselects leave the row picked since
    alone.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_select_model.c        | 57 +++++++++++++++++++----
 src/tests/elementary/efl_ui_test_select_model.c | 61 +++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 8 deletions(-)

diff --git a/src/lib/elementary/efl_ui_select_model.c b/src/lib/elementary/efl_ui_select_model.c
index e84fac06dd..1d69c9a232 100644
--- a/src/lib/elementary/efl_ui_select_model.c
+++ b/src/lib/elementary/efl_ui_select_model.c
@@ -31,6 +31,10 @@ struct _Efl_Ui_Select_Model_Data
    Eina_Bool allow_manual_deselection : 1;
 };
 
+static void _unselect_range(Eo *obj, unsigned int a, unsigned int b,
+                            Eina_Value (*then)(Eo *o, void *data, const Eina_Value v));
+static Eina_Value _children_unselect_keep_picked_then(Eo *o, void *data, const Eina_Value v);
+
 static void
 _efl_ui_select_model_apply_last_model(Eo *obj, Efl_Ui_Select_Model_Data *pd, Eo *last_model)
 {
@@ -428,8 +432,12 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
         if ((pd->parent->selection == EFL_UI_SELECT_MODE_NONE) && newflag)
           return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE);
 
-        // Nothing changed
-        if (newflag == prevflag)
+        // Nothing changed. A row still selected from before a switch to single selection,
+        // that is not the selected one, is not that: picking it makes it the one, or the
+        // unselects that follow the switch would take it too.
+        if ((newflag == prevflag) &&
+            !(newflag && (pd->parent->selection == EFL_UI_SELECT_MODE_SINGLE) &&
+              (pd->parent->last_model != obj)))
           return efl_loop_future_resolved(obj, eina_value_bool_init(newflag));
 
         // (a select that changes nothing does not take the place of one by index in flight)
@@ -631,8 +639,11 @@ _select_keep_one(Eo *obj, Efl_Ui_Select_Model_Data *pd)
    if (!any) return;
 
    count = efl_model_children_count_get(obj);
-   if (keep > 0) efl_ui_multi_selectable_ndx_range_unselect(obj, 0, keep - 1);
-   if (keep < count - 1) efl_ui_multi_selectable_ndx_range_unselect(obj, keep + 1, count - 1);
+   if (keep > 0) _unselect_range(obj, 0, keep - 1, _children_unselect_keep_picked_then);
+   if (keep < (count - 1))
+     {
+        _unselect_range(obj, keep + 1, count - 1, _children_unselect_keep_picked_then);
+     }
 
    if (pd->last_model && (efl_composite_model_index_get(pd->last_model) == keep)) return;
    efl_future_then(obj, efl_model_children_slice_get(obj, keep, 1),
@@ -751,12 +762,34 @@ _children_unselect_then(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Va
    return v;
 }
 
+// The rows left over when leaving multiple selection: the one picked since, which is the
+// selected one now, stays.
+static Eina_Value
+_children_unselect_keep_picked_then(Eo *o, void *data EINA_UNUSED, const Eina_Value v)
+{
+   Efl_Ui_Select_Model_Data *pd = efl_data_scope_get(o, EFL_UI_SELECT_MODEL_CLASS);
+   Eo *target;
+   Eina_Value unselect;
+   unsigned int i, len;
+
+   unselect = eina_value_bool_init(EINA_FALSE);
+
+   EINA_VALUE_ARRAY_FOREACH(&v, len, i, target)
+     {
+        if ((pd->selection == EFL_UI_SELECT_MODE_SINGLE) && (pd->last_model == target)) continue;
+        efl_model_property_set(target, "self.selected", &unselect);
+     }
+
+   eina_value_flush(&unselect);
+
+   return v;
+}
+
 #define BATCH_MAX 100
 
 static void
-_efl_ui_select_model_efl_ui_multi_selectable_index_range_ndx_range_unselect(Eo *obj,
-                                                                            Efl_Ui_Select_Model_Data *pd EINA_UNUSED,
-                                                                            unsigned int a, unsigned int b)
+_unselect_range(Eo *obj, unsigned int a, unsigned int b,
+                Eina_Value (*then)(Eo *o, void *data, const Eina_Value v))
 {
    unsigned long count, batch, i;
 
@@ -783,12 +816,20 @@ _efl_ui_select_model_efl_ui_multi_selectable_index_range_ndx_range_unselect(Eo *
 
         f = efl_model_children_slice_get(obj, i, batch);
         efl_future_then(obj, f, .success_type = EINA_VALUE_TYPE_ARRAY,
-                        .success = _children_unselect_then);
+                        .success = then);
 
         i += batch;
      }
 }
 
+static void
+_efl_ui_select_model_efl_ui_multi_selectable_index_range_ndx_range_unselect(Eo *obj,
+                                                                            Efl_Ui_Select_Model_Data *pd EINA_UNUSED,
+                                                                            unsigned int a, unsigned int b)
+{
+   _unselect_range(obj, a, b, _children_unselect_then);
+}
+
 static void
 _efl_ui_select_model_efl_ui_single_selectable_fallback_selection_set(Eo *obj,
                                                                      Efl_Ui_Select_Model_Data *pd,
diff --git a/src/tests/elementary/efl_ui_test_select_model.c b/src/tests/elementary/efl_ui_test_select_model.c
index bef69de55e..55cd35ab10 100644
--- a/src/tests/elementary/efl_ui_test_select_model.c
+++ b/src/tests/elementary/efl_ui_test_select_model.c
@@ -777,6 +777,66 @@ EFL_START_TEST(efl_test_select_model_noop_select_keeps_index_select)
 }
 EFL_END_TEST
 
+// Leaving multiple selection, then picking one of the rows that were selected, in the same
+// turn: the unselects of the others, which arrive later, must not take the pick away.
+EFL_START_TEST(efl_test_select_model_multi_to_single_pick_a_selected_row)
+{
+   Efl_Model *base_model, *model;
+   Eo *kids[2] = { NULL, NULL };
+   Eina_Value select = eina_value_bool_init(EINA_TRUE);
+   unsigned int i, first = 99;
+
+   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   for (i = 0; i < 6; ++i)
+     {
+        ck_assert(!!efl_model_child_add(base_model));
+     }
+   model = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get(),
+                       efl_ui_view_model_set(efl_added, base_model));
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   eina_future_then(efl_model_children_slice_get(model, 0, 2), _gone_then, kids, NULL);
+   for (i = 0; (i < 12) && !kids[1]; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert(!!kids[1]);
+
+   efl_ui_multi_selectable_ndx_range_select(model, 1, 1);
+   for (i = 0; i < 8; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   efl_ui_multi_selectable_ndx_range_select(model, 4, 4);
+   for (i = 0; i < 8; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   efl_ui_multi_selectable_ndx_range_select(model, 2, 2);
+   for (i = 0; i < 8; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, NULL), 3);
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_SINGLE);
+   eina_future_then(efl_model_property_set(kids[1], "self.selected", &select),
+                    _state_ignore, NULL, NULL);
+   for (i = 0; i < 16; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+   ck_assert_int_eq(first, 1);
+   ck_assert_ptr_ne(efl_ui_selectable_last_selected_get(model), NULL);
+   ck_assert_int_eq(efl_composite_model_index_get(efl_ui_selectable_last_selected_get(model)), 1);
+
+   efl_unref(kids[0]);
+   efl_unref(kids[1]);
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
 void
 efl_ui_test_select_model(TCase *tc)
 {
@@ -793,4 +853,5 @@ efl_ui_test_select_model(TCase *tc)
    tcase_add_test(tc, efl_test_select_model_manual_deselection);
    tcase_add_test(tc, efl_test_select_model_single_later_direct_select_wins);
    tcase_add_test(tc, efl_test_select_model_noop_select_keeps_index_select);
+   tcase_add_test(tc, efl_test_select_model_multi_to_single_pick_a_selected_row);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to