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 56ebb1f86d6e9cad4d8013bf98d6cf6478c48e23
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 10 17:38:36 2026 -0600

    elementary: collection_view: no second item for the new last row
    
    When the last row of a model is removed the row before it becomes the
    last one, and the count change asks for it with an item. If it was on
    screen it has its item already, and the request built another one,
    logging 'Entity already existing' and 'Inserting a model that was
    already fetched'. The item that is there is only remembered as the last
    one now.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_collection_view.c        | 20 ++++++++-
 src/tests/elementary/efl_ui_test_collection_view.c | 52 ++++++++++++++++++++++
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/src/lib/elementary/efl_ui_collection_view.c b/src/lib/elementary/efl_ui_collection_view.c
index 593d79dcb6..b5661db440 100644
--- a/src/lib/elementary/efl_ui_collection_view.c
+++ b/src/lib/elementary/efl_ui_collection_view.c
@@ -2072,8 +2072,24 @@ _efl_model_count_changed(void *data, const Efl_Event *event EINA_UNUSED)
    // The last item is not the last item anymore: fetch the one that is
    if (count)
      {
-        requests = _request_add(requests, &request, count - 1, EINA_TRUE);
-        if (request) requests = eina_list_append(requests, request);
+        Efl_Ui_Collection_Item_Lookup *last;
+        unsigned int last_index = count - 1;
+
+        /* The row that became the last one may already have its item (it
+           was on screen): asking for it again would build a second one.
+           It is only to be remembered as the last. */
+        last = (void*) eina_rbtree_inline_lookup(pd->cache, &last_index,
+                                                 sizeof (last_index), _cache_tree_lookup,
+                                                 NULL);
+        if (last && last->item.entity)
+          {
+             _last_entity_update(pd, last->item.entity);
+          }
+        else
+          {
+             requests = _request_add(requests, &request, last_index, EINA_TRUE);
+             if (request) requests = eina_list_append(requests, request);
+          }
      }
    requests = _batch_request_flush(requests, data, pd);
 
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index 71802611dd..a26524de73 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -929,6 +929,57 @@ EFL_START_TEST(efl_ui_collection_view_manager_ownership)
 }
 EFL_END_TEST
 
+/* The last row of a model bound to a live view is removed: the view
+   must not find an item or an entity left for a row that is gone. */
+EFL_START_TEST(test_efl_ui_collection_view_remove_last_row)
+{
+   Efl_Ui_Win *win;
+   Efl_Model *model, *rows[NUM_ITEMS];
+   int total = 4;
+   Efl_Ui_List_View *lv;
+   Efl_Ui_Factory *fl;
+   Eina_Value v;
+   int errors = 0, i, n;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 100));
+
+   model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
+   eina_value_setup(&v, EINA_VALUE_TYPE_STRING);
+   eina_value_set(&v, "Row");
+   for (i = 0; i < total; i++)
+     {
+        rows[i] = efl_model_child_add(model);
+        efl_model_property_set(rows[i], "title", &v);
+     }
+   eina_value_flush(&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_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();
+     }
+
+   eina_log_print_cb_set(_count_err_cri, &errors);
+   for (n = 0; n < 3; n++)
+     {
+        efl_model_child_del(model, rows[total - 1 - n]);
+        for (i = 0; i < 50; i++)
+          {
+             ecore_main_loop_iterate();
+          }
+     }
+   eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
+   ck_assert_int_eq(errors, 0);
+}
+EFL_END_TEST
+
 void efl_ui_test_collection_view(TCase *tc)
 {
    tcase_add_test(tc, test_efl_ui_collection_view_basic);
@@ -947,4 +998,5 @@ void efl_ui_test_collection_view(TCase *tc)
    tcase_add_test(tc, test_efl_ui_collection_view_homogeneous_model);
    tcase_add_test(tc, test_efl_ui_collection_view_item_events_without_info);
    tcase_add_test(tc, test_efl_ui_collection_view_sizes_agree);
+   tcase_add_test(tc, test_efl_ui_collection_view_remove_last_row);
 }

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

Reply via email to