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 a96d998e1fd06c7cb9a3ea64a1f02531ec631d05
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:31:50 2026 -0600

    elementary: select_model: the last pick wins over earlier unselects
    
    Picking A, B and then A again in one turn made the two chains unselect
    each other: B's unselect of A ran once A was the selected one again, and
    took it. That unselect now leaves the row that is the selected one
    alone, so the last pick stays.
    
    Going to none queued the unselects of every row, and they arrived after
    a row picked in the meantime (none then single or multi, then a pick in
    one turn): with the clear flag set they skip the refusal and the
    fallback, so the pick was lost. Each pick now records its place in a
    sequence, and the clear leaves the rows picked after it was asked for.
    The sequence wraps around and 0 means a row never picked, so the
    sequence skips it.
    
    The pick is recorded whenever the new value is true, before the early
    return of a select that changes nothing, but only once nothing can fail
    the select, so a refused select leaves no pick behind and does not count
    as a selection by index in flight.
    
    The picks are kept by the parent, in a table sorted by row index and
    moved up and down when a row is added or removed, not on the rows: a row
    goes away when nothing holds it, and the one a later slice builds for
    the same index has to be known as picked. A pick is only of use to a
    clear asked for before it, so the table is only filled while a clear is
    pending (counted per batch of rows the clear fetched), let go of when
    the count is back to 0, when going to none queues the clear and on
    invalidate. Without that, all_select on 100k rows kept 100k entries for
    the life of the model and every row added or removed shifted all of
    them.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_select_model.c        | 238 ++++++-
 src/tests/elementary/efl_ui_test_select_model.c | 813 +++++++++++++++++++-----
 2 files changed, 876 insertions(+), 175 deletions(-)

diff --git a/src/lib/elementary/efl_ui_select_model.c b/src/lib/elementary/efl_ui_select_model.c
index 8786211654..5ccd9b9091 100644
--- a/src/lib/elementary/efl_ui_select_model.c
+++ b/src/lib/elementary/efl_ui_select_model.c
@@ -22,11 +22,23 @@ struct _Efl_Ui_Select_Model_Data
 
    Efl_Ui_Select_Model *fallback_model;
    Efl_Ui_Select_Model *last_model;
+   // The change_seq (never 0) of the last pick of each row that was picked, by row index and
+   // sorted by it. Parent only. It is kept here and not on the rows: a row nobody holds a
+   // reference to goes away, and the one built for the same index later has to be known as picked.
+   // Only kept while a clear is pending (see pending_clears): a pick is only of use to a
+   // clear asked for before it, and without one the table is not made.
+   Eina_Inarray *picks;
 
    Efl_Ui_Select_Mode selection;
    // Counts the selections asked for: one by index fetches its row first, and in single mode
    // a selection asked for meanwhile is the later one
    unsigned int select_seq;
+   // Counts the picks and the clears: a clear (going to none) unselects what was selected
+   // when it was asked for, not what was picked after. Parent only.
+   unsigned int change_seq;
+   // The clears that are not applied yet: one for each batch of rows that going to none
+   // fetched and did not unselect yet. Parent only. The picks table is let go of at 0.
+   unsigned int pending_clears;
 
    Eina_Bool allow_manual_deselection : 1;
    // Set while the unselects that going to none asks for are applied: they are not a manual
@@ -34,8 +46,16 @@ struct _Efl_Ui_Select_Model_Data
    Eina_Bool clearing : 1;
 };
 
-static void _unselect_range(Eo *obj, unsigned int a, unsigned int b,
-                            Eina_Value (*then)(Eo *o, void *data, const Eina_Value v));
+typedef struct
+{
+   unsigned int index;
+   unsigned int seq;
+} Select_Pick;
+
+typedef Eina_Value (*Unselect_Cb)(Eo *o, void *data, const Eina_Value v);
+
+static void _unselect_range(Eo *obj, unsigned int a, unsigned int b, Unselect_Cb then,
+                            void *data, Eina_Bool clear);
 static Eina_Value _children_unselect_keep_picked_then(Eo *o, void *data, const Eina_Value v);
 static Eina_Value _children_unselect_clear_then(Eo *o, void *data, const Eina_Value v);
 
@@ -46,12 +66,131 @@ _efl_ui_select_model_apply_last_model(Eo *obj, Efl_Ui_Select_Model_Data *pd, Eo
    efl_model_properties_changed(obj, "child.selected");
 }
 
+// A batch of a clear is applied (or gone): with the last one the picks are of no use
+static void
+_clear_done(Efl_Ui_Select_Model_Data *pd)
+{
+   if (!pd->pending_clears) return;
+   if (--pd->pending_clears) return;
+   eina_inarray_free(pd->picks);
+   pd->picks = NULL;
+}
+
+// The next place in the sequence of the picks and the clears. 0 is not one: it is what a row
+// never picked has, and the sequence wraps around.
+static unsigned int
+_change_seq_next(Efl_Ui_Select_Model_Data *pd)
+{
+   if (++pd->change_seq == 0) pd->change_seq = 1;
+   return pd->change_seq;
+}
+
+// The place of the pick of index in the sorted picks, or where it would be inserted
+static unsigned int
+_picks_find(const Efl_Ui_Select_Model_Data *pd, unsigned int index, Eina_Bool *found)
+{
+   unsigned int lo = 0, hi = eina_inarray_count(pd->picks);
+
+   while (lo < hi)
+     {
+        unsigned int mid = lo + (hi - lo) / 2;
+        const Select_Pick *p = eina_inarray_nth(pd->picks, mid);
+
+        if (p->index < index)
+          {
+             lo = mid + 1;
+          }
+        else
+          {
+             hi = mid;
+          }
+     }
+   *found = (lo < eina_inarray_count(pd->picks)) &&
+     (((const Select_Pick *) eina_inarray_nth(pd->picks, lo))->index == index);
+   return lo;
+}
+
+// The change_seq of the last pick of the row at index, 0 for a row never picked
+static unsigned int
+_pick_get(const Efl_Ui_Select_Model_Data *pd, unsigned int index)
+{
+   Eina_Bool found;
+   unsigned int at;
+
+   if (!pd->picks) return 0;
+   at = _picks_find(pd, index, &found);
+   if (!found) return 0;
+   return ((const Select_Pick *) eina_inarray_nth(pd->picks, at))->seq;
+}
+
+// Records the pick of the row at index. Memory for it is not a reason to refuse a
+// select: the row is then not known as picked after a clear, which is what was before.
+static void
+_pick_set(Efl_Ui_Select_Model_Data *pd, unsigned int index, unsigned int seq)
+{
+   Select_Pick pick = { index, seq };
+   Eina_Bool found;
+   unsigned int at;
+
+   if (index == 0xFFFFFFFF) return;
+   // No clear waiting for it: nothing is going to ask whether this row was picked
+   if (!pd->pending_clears) return;
+   if (!pd->picks)
+     {
+        pd->picks = eina_inarray_new(sizeof (Select_Pick), 8);
+        if (!pd->picks) return;
+     }
+   at = _picks_find(pd, index, &found);
+   if (found)
+     {
+        ((Select_Pick *) eina_inarray_nth(pd->picks, at))->seq = seq;
+        return;
+     }
+   eina_inarray_insert_at(pd->picks, at, &pick);
+}
+
+// A row came (added) or went at index: the rows above are one further or one closer
+static void
+_picks_shift(Efl_Ui_Select_Model_Data *pd, unsigned int index, Eina_Bool added)
+{
+   Eina_Bool found;
+   unsigned int at, i, count;
+
+   if (!pd->picks) return;
+   at = _picks_find(pd, index, &found);
+   if (found && !added) eina_inarray_remove_at(pd->picks, at);
+   count = eina_inarray_count(pd->picks);
+   for (i = at; i < count; i++)
+     {
+        Select_Pick *p = eina_inarray_nth(pd->picks, i);
+
+        if (added)
+          {
+             p->index++;
+          }
+        else
+          {
+             p->index--;
+          }
+     }
+}
+
+static void
+_efl_ui_select_model_child_added(void *data, const Efl_Event *event)
+{
+   Efl_Ui_Select_Model_Data *pd = data;
+   Efl_Model_Children_Event *ev = event->info;
+
+   if (!pd->parent) _picks_shift(pd, ev->index, EINA_TRUE);
+}
+
 static void
 _efl_ui_select_model_child_removed(void *data, const Efl_Event *event)
 {
    Efl_Ui_Select_Model_Data *pd = data;
    Efl_Model_Children_Event *ev = event->info;
 
+   if (!pd->parent) _picks_shift(pd, ev->index, EINA_FALSE);
    if (ev->child == pd->last_model)
      _efl_ui_select_model_apply_last_model(event->object, pd, NULL);
 }
@@ -66,6 +205,7 @@ _efl_ui_select_model_efl_object_constructor(Eo *obj,
 
    efl_boolean_model_boolean_add(obj, "selected", EINA_FALSE);
 
+   efl_event_callback_add(obj, EFL_MODEL_EVENT_CHILD_ADDED, _efl_ui_select_model_child_added, pd);
    efl_event_callback_add(obj, EFL_MODEL_EVENT_CHILD_REMOVED, _efl_ui_select_model_child_removed, pd);
 
    /* Same default as Efl.Ui.Collection: unselecting what is selected is
@@ -85,6 +225,10 @@ _efl_ui_select_model_efl_object_invalidate(Eo *obj,
 {
    efl_replace(&pd->fallback_model, NULL);
    efl_replace(&pd->last_model, NULL);
+   eina_inarray_free(pd->picks);
+   pd->picks = NULL;
+   // (no clear is waiting for a pick of a model that is gone: none is to make the table again)
+   pd->pending_clears = 0;
 
    efl_invalidate(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS));
 }
@@ -287,16 +431,20 @@ _select_slice_then(Eo *obj,
 }
 
 static Eina_Value
-_unselect_slice_then(Eo *obj EINA_UNUSED,
+_unselect_slice_then(Eo *obj,
                      void *data EINA_UNUSED,
                      const Eina_Value v)
 {
+   Efl_Ui_Select_Model_Data *pd = efl_data_scope_get(obj, EFL_UI_SELECT_MODEL_CLASS);
    Efl_Model *child = NULL;
    Eina_Future *r;
 
    child = _select_child_get(&v, 0);
    if (!child) goto on_error;
 
+   // The row picked again since is the selected one: it is not the one to unselect
+   if (pd && (pd->last_model == child)) return v;
+
    r = _unselect_child(child);
    return eina_future_as_value(r);
 
@@ -495,12 +643,16 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
         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)
-        if (newflag)
           {
-             pd->parent->select_seq++;
+             // Picked whether or not it changes anything: a clear asked for before takes
+             // the rows selected then, and this one is not one of them (it was selected
+             // before the clear and is picked again after it).
+             if (newflag)
+               {
+                  _pick_set(pd->parent, efl_composite_model_index_get(obj),
+                            _change_seq_next(pd->parent));
+               }
+             return efl_loop_future_resolved(obj, eina_value_bool_init(newflag));
           }
 
         /* Refusing to be the change that leaves nothing selected, which is
@@ -529,6 +681,17 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
              if (!untangle) return efl_loop_future_rejected(obj, ENOMEM);
           }
 
+        // Picked, once nothing can fail the select any more: a select that was refused
+        // is not a pick
+        if (newflag)
+          {
+             _pick_set(pd->parent, efl_composite_model_index_get(obj),
+                       _change_seq_next(pd->parent));
+             // (a select that changes nothing does not take the place of one by index
+             // in flight, nor does one that failed to start)
+             pd->parent->select_seq++;
+          }
+
         // First store the new value in the boolean model we inherit from
         chain = efl_model_property_set(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS),
                                        "selected", value);
@@ -705,10 +868,14 @@ _select_keep_one(Eo *obj, Efl_Ui_Select_Model_Data *pd)
    if (!any) return;
 
    count = efl_model_children_count_get(obj);
-   if (keep > 0) _unselect_range(obj, 0, keep - 1, _children_unselect_keep_picked_then);
+   if (keep > 0)
+     {
+        _unselect_range(obj, 0, keep - 1, _children_unselect_keep_picked_then, NULL, EINA_FALSE);
+     }
    if (keep < (count - 1))
      {
-        _unselect_range(obj, keep + 1, count - 1, _children_unselect_keep_picked_then);
+        _unselect_range(obj, keep + 1, count - 1, _children_unselect_keep_picked_then,
+                        NULL, EINA_FALSE);
      }
 
    if (pd->last_model && (efl_composite_model_index_get(pd->last_model) == keep)) return;
@@ -734,7 +901,13 @@ _efl_ui_select_model_efl_ui_multi_selectable_select_mode_set(Eo *obj,
          {
             unsigned int count = efl_model_children_count_get(obj);
 
-            if (count) _unselect_range(obj, 0, count - 1, _children_unselect_clear_then);
+            if (count)
+              _unselect_range(obj, 0, count - 1, _children_unselect_clear_then,
+                              (void *) (uintptr_t) _change_seq_next(pd), EINA_TRUE);
+            // Every pick so far is older than this clear, which is all the table is asked
+            // for: it is of no use any more
+            eina_inarray_free(pd->picks);
+            pd->picks = NULL;
          }
          break;
       case EFL_UI_SELECT_MODE_MULTI:
@@ -855,26 +1028,49 @@ _children_unselect_keep_picked_then(Eo *o, void *data EINA_UNUSED, const Eina_Va
    return v;
 }
 
-// What going to none unselects, which allow_manual_deselection does not refuse
+// What going to none unselects, which allow_manual_deselection does not refuse. The rows
+// picked since (data is the change_seq of the clear) are not part of it.
 static Eina_Value
 _children_unselect_clear_then(Eo *o, void *data, const Eina_Value v)
 {
    Efl_Ui_Select_Model_Data *pd = efl_data_scope_get(o, EFL_UI_SELECT_MODEL_CLASS);
-   Eina_Value r;
+   unsigned int seq = (unsigned int) (uintptr_t) data;
+   Eina_Value unselect = eina_value_bool_init(EINA_FALSE);
+   Eo *target;
+   unsigned int i, len;
 
    pd->clearing = EINA_TRUE;
-   r = _children_unselect_then(o, data, v);
-   pd->clearing = EINA_FALSE;
+   EINA_VALUE_ARRAY_FOREACH(&v, len, i, target)
+     {
+        unsigned int pick = _pick_get(pd, efl_composite_model_index_get(target));
 
-   return r;
+        // (0 is a row never picked, which is not newer than anything)
+        if (pick && ((int) (pick - seq) > 0)) continue;
+        efl_model_property_set(target, "self.selected", &unselect);
+     }
+   pd->clearing = EINA_FALSE;
+   eina_value_flush(&unselect);
+   _clear_done(pd);
+
+   return v;
+}
+
+// A clear that failed to fetch its rows is not going to ask for the picks either
+static Eina_Value
+_children_unselect_clear_error(Eo *o, void *data EINA_UNUSED, Eina_Error err)
+{
+   Efl_Ui_Select_Model_Data *pd = efl_data_scope_get(o, EFL_UI_SELECT_MODEL_CLASS);
+
+   _clear_done(pd);
+   return eina_value_error_init(err);
 }
 
 #define BATCH_MAX 100
 
 static void
-_unselect_range(Eo *obj, unsigned int a, unsigned int b,
-                Eina_Value (*then)(Eo *o, void *data, const Eina_Value v))
+_unselect_range(Eo *obj, unsigned int a, unsigned int b, Unselect_Cb then, void *data, Eina_Bool clear)
 {
+   Efl_Ui_Select_Model_Data *pd = efl_data_scope_get(obj, EFL_UI_SELECT_MODEL_CLASS);
    unsigned long count, batch, i;
 
    if (a > b)
@@ -899,8 +1095,10 @@ _unselect_range(Eo *obj, unsigned int a, unsigned int b,
         batch -= i;
 
         f = efl_model_children_slice_get(obj, i, batch);
+        if (clear && f) pd->pending_clears++;
         efl_future_then(obj, f, .success_type = EINA_VALUE_TYPE_ARRAY,
-                        .success = then);
+                        .success = then, .data = ""
+                        .error = clear ? _children_unselect_clear_error : NULL);
 
         i += batch;
      }
@@ -911,7 +1109,7 @@ _efl_ui_select_model_efl_ui_multi_selectable_index_range_ndx_range_unselect(Eo *
                                                                             Efl_Ui_Select_Model_Data *pd EINA_UNUSED,
                                                                             unsigned int a, unsigned int b)
 {
-   _unselect_range(obj, a, b, _children_unselect_then);
+   _unselect_range(obj, a, b, _children_unselect_then, NULL, EINA_FALSE);
 }
 
 static void
diff --git a/src/tests/elementary/efl_ui_test_select_model.c b/src/tests/elementary/efl_ui_test_select_model.c
index faf51a7ddf..1100b82e0d 100644
--- a/src/tests/elementary/efl_ui_test_select_model.c
+++ b/src/tests/elementary/efl_ui_test_select_model.c
@@ -237,9 +237,99 @@ EFL_START_TEST(efl_test_select_model_reversed_range)
 }
 EFL_END_TEST
 
-/* Leaving multiple selection for single keeps the row that was selected last, as
- * Efl.Ui.Collection does (it keeps the last of its selected items), and unselects the
- * others. Going to none unselects everything, in both. */
+/* In single mode, allow_manual_deselection decides whether the model may end
+ * up with nothing selected. It defaults to allowing it, the same as
+ * Efl.Ui.Collection does; turning it off makes the last selection stick.
+ *
+ * This is checked on the model directly rather than through a view: the
+ * property is documented in terms of clicking, but a model has no clicks, and
+ * a model driven from code has to behave the same way. */
+EFL_START_TEST(efl_test_select_model_manual_deselection)
+{
+   Efl_Model *base_model, *model, *child;
+   Eina_Value v = EINA_VALUE_EMPTY;
+   Eina_Value *readback;
+   Eina_Bool selected = EINA_FALSE;
+   int i;
+
+   eina_value_setup(&v, EINA_VALUE_TYPE_INT);
+
+   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   ck_assert(!!base_model);
+
+   for (i = 0; i < 3; ++i)
+     {
+        child = efl_model_child_add(base_model);
+        ck_assert(!!child);
+        ck_assert(eina_value_set(&v, i));
+        efl_model_property_set(child, "test_p_int", &v);
+     }
+
+   model = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get(),
+                       efl_ui_view_model_set(efl_added, base_model));
+   ck_assert(!!model);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_SINGLE);
+
+   /* Allowed by default, as Efl.Ui.Collection has it. */
+   ck_assert_int_eq(efl_ui_selectable_allow_manual_deselection_get(model), EINA_TRUE);
+
+   efl_ui_selectable_allow_manual_deselection_set(model, EINA_FALSE);
+   ck_assert_int_eq(efl_ui_selectable_allow_manual_deselection_get(model), EINA_FALSE);
+
+   /* Select one, then try to give it back. */
+   v = eina_value_int_init(1);
+   efl_model_property_set(model, "child.selected", &v);
+   ecore_main_loop_iterate();
+
+   {
+      Eina_Value keep = eina_value_bool_init(EINA_FALSE);
+      Efl_Model *sel = efl_ui_selectable_last_selected_get(model);
+
+      ck_assert_ptr_ne(sel, NULL);
+      efl_model_property_set(sel, "self.selected", &keep);
+      eina_value_flush(&keep);
+      ecore_main_loop_iterate();
+      ecore_main_loop_iterate();
+
+      readback = efl_model_property_get(sel, "selected");
+      ck_assert_ptr_ne(readback, NULL);
+      eina_value_bool_get(readback, &selected);
+      eina_value_free(readback);
+
+      /* Refused: something is still selected. */
+      ck_assert_int_eq(selected, EINA_TRUE);
+      ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(model), sel);
+   }
+
+   eina_value_flush(&v);
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
+static Eina_Bool
+_state_get(Eo *child, const char *name)
+{
+   Eina_Value *r = efl_model_property_get(child, name);
+   Eina_Bool b = EINA_FALSE;
+
+   ck_assert(!!r);
+   ck_assert(eina_value_type_get(r) == EINA_VALUE_TYPE_BOOL);
+   eina_value_bool_get(r, &b);
+   eina_value_free(r);
+   return b;
+}
+
+static Eina_Value
+_state_ignore(void *data EINA_UNUSED, const Eina_Value v,
+              const Eina_Future *dead_future EINA_UNUSED)
+{
+   return v;
+}
+
+// Leaving multiple selection for single keeps the row that was selected last, as
+// Efl.Ui.Collection does (it keeps the last of its selected items), and unselects the
+// others. Going to none unselects everything, in both.
 static unsigned int
 _selected_count(Efl_Ui_Select_Model *model, unsigned int *first)
 {
@@ -608,83 +698,6 @@ EFL_START_TEST(efl_test_select_model_gone_row_is_not_selected)
 }
 EFL_END_TEST
 
-/* In single mode, allow_manual_deselection decides whether the model may end
- * up with nothing selected. It defaults to allowing it, the same as
- * Efl.Ui.Collection does; turning it off makes the last selection stick.
- *
- * This is checked on the model directly rather than through a view: the
- * property is documented in terms of clicking, but a model has no clicks, and
- * a model driven from code has to behave the same way. */
-EFL_START_TEST(efl_test_select_model_manual_deselection)
-{
-   Efl_Model *base_model, *model, *child;
-   Eina_Value v = EINA_VALUE_EMPTY;
-   Eina_Value *readback;
-   Eina_Bool selected = EINA_FALSE;
-   int i;
-
-   eina_value_setup(&v, EINA_VALUE_TYPE_INT);
-
-   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
-   ck_assert(!!base_model);
-
-   for (i = 0; i < 3; ++i)
-     {
-        child = efl_model_child_add(base_model);
-        ck_assert(!!child);
-        ck_assert(eina_value_set(&v, i));
-        efl_model_property_set(child, "test_p_int", &v);
-     }
-
-   model = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get(),
-                       efl_ui_view_model_set(efl_added, base_model));
-   ck_assert(!!model);
-   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_SINGLE);
-
-   /* Allowed by default, as Efl.Ui.Collection has it. */
-   ck_assert_int_eq(efl_ui_selectable_allow_manual_deselection_get(model), EINA_TRUE);
-
-   efl_ui_selectable_allow_manual_deselection_set(model, EINA_FALSE);
-   ck_assert_int_eq(efl_ui_selectable_allow_manual_deselection_get(model), EINA_FALSE);
-
-   /* Select one, then try to give it back. */
-   v = eina_value_int_init(1);
-   efl_model_property_set(model, "child.selected", &v);
-   ecore_main_loop_iterate();
-
-   {
-      Eina_Value keep = eina_value_bool_init(EINA_FALSE);
-      Efl_Model *sel = efl_ui_selectable_last_selected_get(model);
-
-      ck_assert_ptr_ne(sel, NULL);
-      efl_model_property_set(sel, "self.selected", &keep);
-      eina_value_flush(&keep);
-      ecore_main_loop_iterate();
-      ecore_main_loop_iterate();
-
-      readback = efl_model_property_get(sel, "selected");
-      ck_assert_ptr_ne(readback, NULL);
-      eina_value_bool_get(readback, &selected);
-      eina_value_free(readback);
-
-      /* Refused: something is still selected. */
-      ck_assert_int_eq(selected, EINA_TRUE);
-      ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(model), sel);
-   }
-
-   eina_value_flush(&v);
-   efl_unref(model);
-   efl_unref(base_model);
-}
-EFL_END_TEST
-
-static Eina_Value
-_state_ignore(void *data EINA_UNUSED, const Eina_Value v,
-              const Eina_Future *dead_future EINA_UNUSED)
-{
-   return v;
-}
-
 // Single mode: a row selected directly (a click) after a selection by index was asked for,
 // before that one fetched its row, is the later one and wins.
 EFL_START_TEST(efl_test_select_model_single_later_direct_select_wins)
@@ -838,7 +851,7 @@ EFL_START_TEST(efl_test_select_model_multi_to_single_pick_a_selected_row)
 EFL_END_TEST
 
 static Eina_Value
-_rows_then(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
+_four_rows_then(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
 {
    Eo **rows = data;
    unsigned int i, len;
@@ -867,7 +880,7 @@ EFL_START_TEST(efl_test_select_model_fallback_after_direct_unselect)
    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_SINGLE);
-   eina_future_then(efl_model_children_slice_get(model, 0, 4), _rows_then, rows, NULL);
+   eina_future_then(efl_model_children_slice_get(model, 0, 4), _four_rows_then, rows, NULL);
    for (i = 0; (i < 12) && !rows[3]; i++)
      {
         ecore_main_loop_iterate();
@@ -902,74 +915,6 @@ EFL_START_TEST(efl_test_select_model_fallback_after_direct_unselect)
 }
 EFL_END_TEST
 
-static Eina_Bool
-_state_get(Eo *child, const char *name)
-{
-   Eina_Value *r = efl_model_property_get(child, name);
-   Eina_Bool b = EINA_FALSE;
-
-   ck_assert(!!r);
-   ck_assert(eina_value_type_get(r) == EINA_VALUE_TYPE_BOOL);
-   eina_value_bool_get(r, &b);
-   eina_value_free(r);
-   return b;
-}
-
-// A select that is cancelled while it waits for the unselect of the row before is rolled back:
-// the new row is not selected, so it is not the last selected one either, and the row before
-// is the selected one still.
-EFL_START_TEST(efl_test_select_model_failed_unselect_rolls_back_last)
-{
-   Efl_Model *base_model, *model;
-   Eo *rows[3] = { NULL, NULL, NULL };
-   Eina_Value select = eina_value_bool_init(EINA_TRUE);
-   unsigned int i;
-
-   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
-   for (i = 0; i < 3; ++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_SINGLE);
-   eina_future_then(efl_model_children_slice_get(model, 0, 3), _rows_then, rows, NULL);
-   for (i = 0; (i < 12) && !rows[2]; i++)
-     {
-        ecore_main_loop_iterate();
-     }
-   ck_assert(!!rows[2]);
-
-   efl_ui_multi_selectable_ndx_range_select(model, 2, 2);
-   for (i = 0; i < 12; i++)
-     {
-        ecore_main_loop_iterate();
-     }
-   ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(model), rows[2]);
-
-   eina_future_cancel(efl_model_property_set(rows[0], "self.selected", &select));
-   for (i = 0; i < 16; i++)
-     {
-        ecore_main_loop_iterate();
-     }
-
-   // The new row was taken back: it is not selected, so it is not the last selected one
-   ck_assert_int_eq(_state_get(rows[0], "selected"), EINA_FALSE);
-   // and the row whose unselect failed is still the selected one
-   ck_assert_int_eq(_state_get(rows[2], "selected"), EINA_TRUE);
-   ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(model), rows[2]);
-   ck_assert_int_eq(_selected_count(model, &i), 1);
-   ck_assert_int_eq(i, 2);
-
-   for (i = 0; i < 3; i++)
-     {
-        efl_unref(rows[i]);
-     }
-   efl_unref(model);
-   efl_unref(base_model);
-}
-EFL_END_TEST
-
 // Going to none unselects every row, whatever allow_manual_deselection says: that is not a
 // person giving up the selection but the mode taking it away. Back in single mode nothing
 // is selected, whether the mode came back at once or after the unselects ran.
@@ -1015,24 +960,582 @@ EFL_START_TEST(efl_test_select_model_none_clears_without_manual_deselection)
 }
 EFL_END_TEST
 
+// A row selected before a clear, picked again once the mode is back, in the same turn: the
+// pick is the later one, and the queued clear must leave it.
+static void
+_repick_after_clear(Efl_Ui_Select_Mode mode)
+{
+   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, mode);
+   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]);
+
+   eina_future_then(efl_model_property_set(kids[1], "self.selected", &select),
+                    _state_ignore, NULL, NULL);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+   ck_assert_int_eq(first, 1);
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, mode);
+   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);
+
+   efl_unref(kids[0]);
+   efl_unref(kids[1]);
+   efl_unref(model);
+   efl_unref(base_model);
+}
+
+EFL_START_TEST(efl_test_select_model_multi_repick_after_clear)
+{
+   _repick_after_clear(EFL_UI_SELECT_MODE_MULTI);
+}
+EFL_END_TEST
+
+EFL_START_TEST(efl_test_select_model_single_repick_after_clear)
+{
+   _repick_after_clear(EFL_UI_SELECT_MODE_SINGLE);
+}
+EFL_END_TEST
+
+// The same with nothing holding the row once it is picked: the object of a row that nobody
+// refs goes away, and the clear, whose slice resolves on a later pass, builds a new one for
+// the same index, which must still be known as picked after the clear.
+EFL_START_TEST(efl_test_select_model_repick_after_clear_rows_not_held)
+{
+   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]);
+
+   eina_future_then(efl_model_property_set(kids[1], "self.selected", &select),
+                    _state_ignore, NULL, NULL);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   eina_future_then(efl_model_property_set(kids[1], "self.selected", &select),
+                    _state_ignore, NULL, NULL);
+   // nothing holds the rows any more when the slice of the clear resolves
+   efl_unref(kids[0]);
+   efl_unref(kids[1]);
+   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);
+
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
+static Eina_Value
+_three_rows_then(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
+{
+   Eo **rows = data;
+   unsigned int i, len;
+   Eo *c;
+
+   EINA_VALUE_ARRAY_FOREACH(&v, len, i, c)
+     {
+        if (i < 3) rows[i] = efl_ref(c);
+     }
+   return v;
+}
+
+// The pick of a row follows the row when one before it leaves: it is the pick of the row at
+// its new index, not of whatever comes to the old one.
+EFL_START_TEST(efl_test_select_model_pick_follows_removed_row)
+{
+   Efl_Model *base_model, *model, *rows[6];
+   Eo *kids[3] = { NULL, 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)
+     {
+        rows[i] = efl_model_child_add(base_model);
+        ck_assert(!!rows[i]);
+     }
+   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, 3), _three_rows_then, kids, NULL);
+   for (i = 0; (i < 12) && !kids[2]; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert(!!kids[2]);
+
+   eina_future_then(efl_model_property_set(kids[2], "self.selected", &select),
+                    _state_ignore, NULL, NULL);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+   ck_assert_int_eq(first, 2);
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   eina_future_then(efl_model_property_set(kids[2], "self.selected", &select),
+                    _state_ignore, NULL, NULL);
+   efl_model_child_del(base_model, rows[0]);
+   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);
+
+   for (i = 0; i < 3; i++)
+     {
+        efl_unref(kids[i]);
+     }
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
+// A select that is cancelled while it waits for the unselect of the row before is rolled back:
+// the new row is not selected, so it is not the last selected one either, and the row before
+// is the selected one still.
+EFL_START_TEST(efl_test_select_model_failed_unselect_rolls_back_last)
+{
+   Efl_Model *base_model, *model;
+   Eo *rows[3] = { NULL, NULL, NULL };
+   Eina_Value select = eina_value_bool_init(EINA_TRUE);
+   unsigned int i;
+
+   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   for (i = 0; i < 3; ++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_SINGLE);
+   eina_future_then(efl_model_children_slice_get(model, 0, 3), _four_rows_then, rows, NULL);
+   for (i = 0; (i < 12) && !rows[2]; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert(!!rows[2]);
+
+   efl_ui_multi_selectable_ndx_range_select(model, 2, 2);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(model), rows[2]);
+
+   eina_future_cancel(efl_model_property_set(rows[0], "self.selected", &select));
+   for (i = 0; i < 16; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+
+   // The new row was taken back: it is not selected, so it is not the last selected one
+   ck_assert_int_eq(_state_get(rows[0], "selected"), EINA_FALSE);
+   // and the row whose unselect failed is still the selected one
+   ck_assert_int_eq(_state_get(rows[2], "selected"), EINA_TRUE);
+   ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(model), rows[2]);
+   ck_assert_int_eq(_selected_count(model, &i), 1);
+   ck_assert_int_eq(i, 2);
+
+   for (i = 0; i < 3; i++)
+     {
+        efl_unref(rows[i]);
+     }
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
+static Eina_Value
+_rows_then(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
+{
+   Eo **rows = data;
+   unsigned int i, len;
+   Eo *c;
+
+   EINA_VALUE_ARRAY_FOREACH(&v, len, i, c)
+     {
+        if (i < 4) rows[i] = efl_ref(c);
+     }
+   return v;
+}
+
+static Efl_Model *
+_rows_model_new(Efl_Model **base, Eo **rows, Efl_Ui_Select_Mode mode)
+{
+   Efl_Model *model;
+   unsigned int i;
+
+   *base = 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 = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get(),
+                       efl_ui_view_model_set(efl_added, *base));
+   efl_ui_multi_selectable_select_mode_set(model, mode);
+   eina_future_then(efl_model_children_slice_get(model, 0, 4), _rows_then, rows, NULL);
+   for (i = 0; (i < 12) && !rows[3]; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert(!!rows[3]);
+   return model;
+}
+
+static void
+_row_select(Eo *row)
+{
+   Eina_Value select = eina_value_bool_init(EINA_TRUE);
+
+   eina_future_then(efl_model_property_set(row, "self.selected", &select),
+                    _state_ignore, NULL, NULL);
+   eina_value_flush(&select);
+}
+
+static void
+_rows_free(Efl_Model *model, Efl_Model *base, Eo **rows)
+{
+   unsigned int i;
+
+   for (i = 0; i < 4; i++)
+     {
+        efl_unref(rows[i]);
+     }
+   efl_unref(model);
+   efl_unref(base);
+}
+
+// Single mode, A selected: picking B and then A again in the same turn leaves the last
+// pick, A, selected, and only it. The unselect B asks for must not take A back.
+EFL_START_TEST(efl_test_select_model_single_pick_a_b_a_same_turn)
+{
+   Efl_Model *base_model, *model;
+   Eo *rows[4] = { NULL, NULL, NULL, NULL };
+   unsigned int i, first = 99;
+
+   model = _rows_model_new(&base_model, rows, EFL_UI_SELECT_MODE_SINGLE);
+   _row_select(rows[1]);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+
+   _row_select(rows[2]);
+   _row_select(rows[1]);
+   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_eq(efl_ui_selectable_last_selected_get(model), rows[1]);
+
+   _rows_free(model, base_model, rows);
+}
+EFL_END_TEST
+
+// Going to none and then back to single, in one turn, and picking a row: the unselects that
+// going to none asked for arrive after the pick, and must not take it.
+EFL_START_TEST(efl_test_select_model_none_single_pick_same_turn)
+{
+   Efl_Model *base_model, *model;
+   Eo *rows[4] = { NULL, NULL, NULL, NULL };
+   unsigned int i, first = 99;
+
+   model = _rows_model_new(&base_model, rows, EFL_UI_SELECT_MODE_SINGLE);
+   _row_select(rows[1]);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_SINGLE);
+   _row_select(rows[3]);
+   for (i = 0; i < 16; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+   ck_assert_int_eq(first, 3);
+   ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(model), rows[3]);
+
+   _rows_free(model, base_model, rows);
+}
+EFL_END_TEST
+
+// The same going back to multiple: the picks stay, what was selected before goes.
+EFL_START_TEST(efl_test_select_model_none_multi_pick_same_turn)
+{
+   Efl_Model *base_model, *model;
+   Eo *rows[4] = { NULL, NULL, NULL, NULL };
+   unsigned int i, first = 99;
+
+   model = _rows_model_new(&base_model, rows, EFL_UI_SELECT_MODE_MULTI);
+   _row_select(rows[1]);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   _row_select(rows[2]);
+   _row_select(rows[3]);
+   for (i = 0; i < 16; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 2);
+   ck_assert_int_eq(first, 2);
+
+   _rows_free(model, base_model, rows);
+}
+EFL_END_TEST
+
+// A row added before a picked row moves its pick with it: a clear asked for before the pick
+// still leaves the row, whatever came to its old index.
+EFL_START_TEST(efl_test_select_model_pick_follows_added_row)
+{
+   Efl_Model *base_model, *model;
+   Efl_Model_Children_Event ev = { 0 };
+   Eo *rows[4] = { NULL, NULL, NULL, NULL };
+   unsigned int i, first = 99;
+
+   model = _rows_model_new(&base_model, rows, EFL_UI_SELECT_MODE_MULTI);
+   _row_select(rows[2]);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   _row_select(rows[2]);
+   // a row comes in at the front, before the picked one (the generic model appends, and
+   // says so; then the row is said to be at the front)
+   ev.child = efl_model_child_add(base_model);
+   ev.index = 0;
+   efl_event_callback_call(base_model, EFL_MODEL_EVENT_CHILD_ADDED, &ev);
+   for (i = 0; i < 16; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+   ck_assert_int_eq(first, 3);
+
+   _rows_free(model, base_model, rows);
+}
+EFL_END_TEST
+
+// The picked row itself leaves: its pick goes with it, and is not the pick of the row that
+// comes to its index. That row was selected before the clear and is not protected.
+EFL_START_TEST(efl_test_select_model_pick_of_removed_row)
+{
+   Efl_Model *base_model, *model;
+   Eo *rows[4] = { NULL, NULL, NULL, NULL };
+   Eo *base_rows[4] = { NULL, NULL, NULL, NULL };
+   unsigned int i;
+
+   model = _rows_model_new(&base_model, rows, EFL_UI_SELECT_MODE_MULTI);
+   _row_select(rows[1]);
+   _row_select(rows[2]);
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, NULL), 2);
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   _row_select(rows[1]);
+   eina_future_then(efl_model_children_slice_get(base_model, 0, 4), _rows_then, base_rows, NULL);
+   for (i = 0; (i < 12) && !base_rows[3]; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert(!!base_rows[3]);
+   efl_model_child_del(base_model, base_rows[1]);
+   for (i = 0; i < 16; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, NULL), 0);
+
+   for (i = 0; i < 4; i++)
+     {
+        efl_unref(base_rows[i]);
+     }
+   _rows_free(model, base_model, rows);
+}
+EFL_END_TEST
+
+// Going to none lets go of the picks, and what is picked after it still survives the clear
+// asked for by it, though the rows were all picked before.
+EFL_START_TEST(efl_test_select_model_none_drops_the_picks)
+{
+   Efl_Model *base_model, *model;
+   Eo *rows[4] = { NULL, NULL, NULL, NULL };
+   unsigned int i, first = 99;
+
+   model = _rows_model_new(&base_model, rows, EFL_UI_SELECT_MODE_MULTI);
+   for (i = 0; i < 4; i++)
+     {
+        _row_select(rows[i]);
+     }
+   for (i = 0; i < 12; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, NULL), 4);
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   for (i = 0; i < 16; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, NULL), 0);
+
+   // None, back to multiple and a pick in one turn: the pick is newer than the clear
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   _row_select(rows[3]);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   _row_select(rows[2]);
+   for (i = 0; i < 16; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, &first), 1);
+   ck_assert_int_eq(first, 2);
+
+   _rows_free(model, base_model, rows);
+}
+EFL_END_TEST
+
+// The time it takes to put rows at the front of a list of the same count, one after
+// the other.
+// A clear that is pending is what makes the picks worth keeping, and the selection after
+// it is only what was picked after it.
+EFL_START_TEST(efl_test_select_model_clear_after_all_select)
+{
+   Efl_Model *base_model, *model;
+   unsigned int i, rows = 200;
+
+   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   for (i = 0; i < rows; 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);
+   efl_ui_multi_selectable_all_select(model);
+   for (i = 0; i < 100; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, NULL), rows);
+
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_NONE);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_MULTI);
+   efl_ui_multi_selectable_ndx_range_select(model, 3, 5);
+   for (i = 0; i < 100; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_selected_count(model, NULL), 3);
+
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
 void
 efl_ui_test_select_model(TCase *tc)
 {
+   tcase_add_test(tc, efl_test_select_model_clear_after_all_select);
    tcase_add_test(tc, efl_test_select_model);
    tcase_add_test(tc, efl_test_select_model_selects_the_first);
    tcase_add_test(tc, efl_test_select_model_reversed_range);
+   tcase_add_test(tc, efl_test_select_model_manual_deselection);
    tcase_add_test(tc, efl_test_select_model_multi_to_single_keeps_last);
    tcase_add_test(tc, efl_test_select_model_single_index_select_replaces);
    tcase_add_test(tc, efl_test_select_model_multi_to_single_keeps_one_without_last);
    tcase_add_test(tc, efl_test_select_model_multi_to_single_select_at_once);
+   tcase_add_test(tc, efl_test_select_model_multi_to_single_pick_a_selected_row);
+   tcase_add_test(tc, efl_test_select_model_single_pick_a_b_a_same_turn);
+   tcase_add_test(tc, efl_test_select_model_none_single_pick_same_turn);
+   tcase_add_test(tc, efl_test_select_model_none_multi_pick_same_turn);
+   tcase_add_test(tc, efl_test_select_model_fallback_after_direct_unselect);
+   tcase_add_test(tc, efl_test_select_model_none_clears_without_manual_deselection);
+   tcase_add_test(tc, efl_test_select_model_multi_repick_after_clear);
+   tcase_add_test(tc, efl_test_select_model_single_repick_after_clear);
+   tcase_add_test(tc, efl_test_select_model_repick_after_clear_rows_not_held);
+   tcase_add_test(tc, efl_test_select_model_pick_follows_removed_row);
+   tcase_add_test(tc, efl_test_select_model_failed_unselect_rolls_back_last);
    tcase_add_test(tc, efl_test_select_model_gone_row_is_not_selected);
    tcase_add_test(tc, efl_test_select_model_single_selects_in_one_turn);
    tcase_add_test(tc, efl_test_select_model_single_to_none_unselects_all);
-   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);
-   tcase_add_test(tc, efl_test_select_model_fallback_after_direct_unselect);
-   tcase_add_test(tc, efl_test_select_model_failed_unselect_rolls_back_last);
-   tcase_add_test(tc, efl_test_select_model_none_clears_without_manual_deselection);
+   tcase_add_test(tc, efl_test_select_model_pick_follows_added_row);
+   tcase_add_test(tc, efl_test_select_model_pick_of_removed_row);
+   tcase_add_test(tc, efl_test_select_model_none_drops_the_picks);
 }

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

Reply via email to