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 655f4d22bf4551b324a0781107821a3f1918b791
Author: Cedric BAIL <[email protected]>
AuthorDate: Mon Oct 26 15:40:54 2026 -0600

    elementary: a collection view refilled shows the new rows, not the old
    
    A view asks for rows by index, and the answer comes later. Nothing
    checked that the index still meant the same row by then. Emptying a
    list and filling it again showed the old rows: the view asks for its
    last row each time the count changes, so it asked for rows 1 and 0
    while the old rows were being taken away. The answers, the old rows'
    models, came once the new rows were in, and were filed and built under
    indexes 1 and 0 as if they were the new rows. An application that
    replaces the whole content of a list, such as a forecast shown for one
    city and then another, showed the previous content this way.
    
    The view now counts its row changes -- rows added, taken away, or
    reordered -- and each request notes the count it was made at. A request
    answered after a change asks again for the same rows instead of using
    what it got, and gives the items it had built back to the factory. A
    request still out from before a change no longer stands in for a new
    one asking for the same rows.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_collection_view.c        | 55 +++++++++++++++
 src/tests/elementary/efl_ui_test_collection_view.c | 80 ++++++++++++++++++++++
 2 files changed, 135 insertions(+)

diff --git a/src/lib/elementary/efl_ui_collection_view.c b/src/lib/elementary/efl_ui_collection_view.c
index f0c34eb869..48b71d40a1 100644
--- a/src/lib/elementary/efl_ui_collection_view.c
+++ b/src/lib/elementary/efl_ui_collection_view.c
@@ -57,6 +57,8 @@ struct _Efl_Ui_Collection_Request
    unsigned int offset;
    unsigned int length;
 
+   unsigned int generation; /* of the rows, when the request was made */
+
    Eina_Bool need_size : 1;
    Eina_Bool need_entity : 1;
    Eina_Bool entity_requested : 1;
@@ -67,6 +69,9 @@ struct _Efl_Ui_Collection_View_Data
    Eina_Bool had_viewport : 1; /* there has been room to show something */
 
    unsigned int last_count; /* to tell a re-order from children arriving */
+   /* Changes whenever rows are added, taken away or reordered, so a row's
+      index may now mean another row. */
+   unsigned int generation;
    Efl_Ui_Factory *factory;
    Efl_Ui_Position_Manager_Entity *manager;
    Efl_Ui_Scroll_Manager *scroller;
@@ -441,6 +446,33 @@ _request_add(Eina_List *requests, Efl_Ui_Collection_Request **request,
    return requests;
 }
 
+static Eina_List *_batch_request_flush(Eina_List *requests,
+                                       Efl_Ui_Collection_View *obj,
+                                       Efl_Ui_Collection_View_Data *pd);
+
+/* A request is for rows by their index, and answers later. If rows were
+   added, taken away or reordered meanwhile, what it got is for rows that
+   may no longer be at those indexes -- a list emptied and filled again
+   would show its old rows. It is made again instead, for the rows there
+   now. */
+static Eina_Bool
+_request_outdated(Efl_Ui_Collection_View *obj, Efl_Ui_Collection_View_Data *pd,
+                  Efl_Ui_Collection_Request *request)
+{
+   Efl_Ui_Collection_Request *again;
+
+   if (request->generation == pd->generation) return EINA_FALSE;
+
+   again = calloc(1, sizeof (Efl_Ui_Collection_Request));
+   if (!again) return EINA_TRUE;
+   again->offset = request->offset;
+   again->length = request->length;
+   again->need_size = request->need_size;
+   again->need_entity = request->need_entity;
+   _batch_request_flush(eina_list_append(NULL, again), obj, pd);
+   return EINA_TRUE;
+}
+
 static Eina_Value
 _model_fetched_cb(Eo *obj, void *data, const Eina_Value v)
 {
@@ -450,6 +482,8 @@ _model_fetched_cb(Eo *obj, void *data, const Eina_Value v)
    unsigned int i, len;
    Eina_Bool request_entity = EINA_FALSE;
 
+   if (_request_outdated(obj, pd, request)) return v;
+
    EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
      {
         Efl_Ui_Collection_Item_Lookup *insert;
@@ -625,6 +659,20 @@ _entity_fetched_cb(Eo *obj, void *data, const Eina_Value v)
    Eina_Bool updated_size = EINA_FALSE, updated_entity = EINA_FALSE;
    Evas *e;
 
+   if (_request_outdated(obj, pd, request))
+     {
+        Eina_Array built;
+
+        eina_array_step_set(&built, sizeof (Eina_Array), 4);
+        EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
+          {
+             eina_array_push(&built, child);
+          }
+        efl_ui_factory_release(pd->factory, eina_array_iterator_new(&built));
+        eina_array_flush(&built);
+        return v;
+     }
+
    e = evas_object_evas_get(obj);
    evas_event_freeze(e);
 
@@ -971,6 +1019,9 @@ _batch_request_flush(Eina_List *requests,
              unsigned int rstart = request->offset;
              unsigned int rend = request->offset + request->length;
 
+             // Fetching rows that may no longer be there: it will ask again
+             if (inflight->generation != pd->generation) continue;
+
              // Way before
              if (rend < istart) continue;
              // Way after
@@ -1058,6 +1109,7 @@ _batch_request_flush(Eina_List *requests,
 
         // We now have a request, time to trigger a fetch
         // We assume here that we are always fetching the model (model_requested must be true)
+        request->generation = pd->generation;
         request->f = efl_model_children_slice_get(model, request->offset, request->length);
         request->f = efl_future_then(obj, request->f,
                                      .success = _model_fetched_cb,
@@ -1994,6 +2046,7 @@ _efl_model_count_changed(void *data, const Efl_Event *event EINA_UNUSED)
       listing would rebuild every visible item over and over. */
    if (count == pd->last_count)
      {
+        pd->generation++;
         _cache_cleanup_above(data, pd, 0);
         if (count)
           efl_ui_position_manager_entity_item_size_changed(pd->manager, 0, count - 1);
@@ -2066,6 +2119,7 @@ _efl_model_child_added(void *data, const Efl_Event *event)
    unsigned int i;
 #endif
 
+   pd->generation++;
    _cache_cleanup_above(data, pd, ev->index);
 
    // Check if we really have something to do
@@ -2144,6 +2198,7 @@ _efl_model_child_removed(void *data, const Efl_Event *event)
 
    // FIXME: later optimization, instead of reloading everyone, we could actually track index and self
    // update would be more efficient, but it is also more tricky
+   pd->generation++;
    _cache_cleanup_above(data, pd, ev->index);
 
    count = efl_model_children_count_get(event->object);
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index 1a845ee697..7a6803ae29 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -341,6 +341,85 @@ EFL_START_TEST(test_efl_ui_collection_view_last_row_kept)
 }
 EFL_END_TEST
 
+/* A list emptied and filled again, as a whole new set of rows replaces the
+   old one, shows the new rows. The view asks for its last row each time
+   the count changes, and those asked for while the old rows went away are
+   answered once the new ones are in: they must not be shown as them. */
+EFL_START_TEST(test_efl_ui_collection_view_refill)
+{
+   Eina_List *realized = NULL;
+   Efl_Ui_Win *win;
+   Efl_Model *model;
+   Efl_Ui_List_View *lv;
+   Efl_Ui_Factory *fl;
+   Eina_Value v;
+   Eo *item, *rows[3];
+   char text[16];
+   int i;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 300));
+
+   model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
+   eina_value_setup(&v, EINA_VALUE_TYPE_STRING);
+   for (i = 0; i < 3; i++)
+     {
+        snprintf(text, sizeof(text), "Row %d", i);
+        eina_value_set(&v, text);
+        rows[i] = efl_model_child_add(model);
+        efl_model_property_set(rows[i], "title", &v);
+     }
+
+   fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
+                efl_ui_property_bind(efl_added, "text", "title"),
+                efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS));
+   lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
+                efl_event_callback_add(efl_added, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_REALIZED,
+                                       _realized_track, &realized),
+                efl_event_callback_add(efl_added, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_UNREALIZED,
+                                       _unrealized_track, &realized),
+                efl_ui_collection_view_factory_set(efl_added, fl),
+                efl_ui_view_model_set(efl_added, model));
+   efl_content_set(win, lv);
+   get_me_to_those_events(lv);
+   for (i = 0; i < 50; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+
+   /* Taken out from the last, then new ones appended. */
+   for (i = 2; i >= 0; i--)
+     {
+        efl_model_child_del(model, rows[i]);
+     }
+   for (i = 0; i < 3; i++)
+     {
+        snprintf(text, sizeof(text), "Row %d", 10 + i);
+        eina_value_set(&v, text);
+        efl_model_property_set(efl_model_child_add(model), "title", &v);
+     }
+   eina_value_flush(&v);
+   for (i = 0; i < 100; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+
+   for (i = 0; i < 3; i++)
+     {
+        snprintf(text, sizeof(text), "Row %d", 10 + i);
+        item = _realized_row(realized, i);
+        ck_assert_ptr_nonnull(item);
+        ck_assert_str_eq(efl_text_get(item), text);
+     }
+
+   efl_event_callback_del(lv, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_REALIZED,
+                          _realized_track, &realized);
+   efl_event_callback_del(lv, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_UNREALIZED,
+                          _unrealized_track, &realized);
+   eina_list_free(realized);
+}
+EFL_END_TEST
+
 /* The sizes the position manager caches and the sizes it places must agree
    while the window resizes the view. */
 EFL_START_TEST(test_efl_ui_collection_view_sizes_agree)
@@ -492,6 +571,7 @@ void efl_ui_test_collection_view(TCase *tc)
    tcase_add_test(tc, test_efl_ui_collection_view_select);
    tcase_add_test(tc, test_efl_ui_collection_view_last_selected_is_an_item);
    tcase_add_test(tc, test_efl_ui_collection_view_last_row_kept);
+   tcase_add_test(tc, test_efl_ui_collection_view_refill);
    tcase_add_test(tc, test_efl_ui_collection_view_tab);
    tcase_add_test(tc, test_efl_ui_collection_view_shift_tab);
    tcase_add_test(tc, test_efl_ui_collection_view_sizes_agree);

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

Reply via email to