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 8ae46d31399732425f453d8a813a95df590e9646
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 6 00:20:02 2026 -0600
ecore: a composite model moves the child at an insert point along
A child added at index k shifted only those above k, so the child that
was at k kept its index and sat in the same place as the new one: the
old row came back as the new one, and what was marked on it landed on
the wrong row. Shift from k on, before the new child is looked for.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/ecore/efl_composite_model.c | 64 ++++++++++++++++++--------------
src/tests/efl/efl_test_composite_model.c | 39 +++++++++++++++++--
2 files changed, 71 insertions(+), 32 deletions(-)
diff --git a/src/lib/ecore/efl_composite_model.c b/src/lib/ecore/efl_composite_model.c
index b04c431b96..b8e9d6b04a 100644
--- a/src/lib/ecore/efl_composite_model.c
+++ b/src/lib/ecore/efl_composite_model.c
@@ -45,21 +45,18 @@ _children_indexed_key(const Efl_Composite_Model_Data *node,
return 0;
}
+// Marks every child whose index is at or above lower.
static void
-_mark_greater(Efl_Composite_Model_Data *root, Eina_Array *mark, const unsigned int upper)
+_mark_from(Efl_Composite_Model_Data *root, Eina_Array *mark, const unsigned int lower)
{
if (!root) return ;
- if (root->index > upper)
+ if (root->index >= lower)
{
eina_array_push(mark, root);
- _mark_greater((void*) EINA_RBTREE_GET(root)->son[0], mark, upper);
- _mark_greater((void*) EINA_RBTREE_GET(root)->son[1], mark, upper);
- }
- else
- {
- _mark_greater((void*) EINA_RBTREE_GET(root)->son[0], mark, upper);
+ _mark_from((void*) EINA_RBTREE_GET(root)->son[1], mark, lower);
}
+ _mark_from((void*) EINA_RBTREE_GET(root)->son[0], mark, lower);
}
static void
@@ -166,6 +163,20 @@ _efl_composite_model_child_event(Efl_Composite_Model_Data *pd,
Eina_Array_Iterator iterator;
unsigned int i;
+ eina_array_step_set(&mark, sizeof (Eina_Array), 8);
+
+ // A child added at an index pushes the one that was there, and all above it, one further.
+ // This has to be done before looking for the new child, or the old one at that index is it.
+ if (description == EFL_MODEL_EVENT_CHILD_ADDED)
+ {
+ _mark_from((void*) pd->indexed, &mark, ev->index);
+ EINA_ARRAY_ITER_NEXT(&mark, i, cpd, iterator)
+ {
+ cpd->index++;
+ efl_ref(cpd->self);
+ }
+ }
+
cev.index = ev->index;
if (ev->child)
{
@@ -179,29 +190,26 @@ _efl_composite_model_child_event(Efl_Composite_Model_Data *pd,
if (cpd) cev.child = efl_ref(cpd->self);
}
- if (cev.child && description == EFL_MODEL_EVENT_CHILD_REMOVED)
+ if (description == EFL_MODEL_EVENT_CHILD_REMOVED)
{
- cpd = efl_data_scope_get(cev.child, EFL_COMPOSITE_MODEL_CLASS);
+ if (cev.child)
+ {
+ cpd = efl_data_scope_get(cev.child, EFL_COMPOSITE_MODEL_CLASS);
- // Remove child from lookup tree if it exist before triggering anything further
- pd->indexed = eina_rbtree_inline_remove(pd->indexed, EINA_RBTREE_GET(cpd),
- EINA_RBTREE_CMP_NODE_CB(_children_indexed_cmp), NULL);
- cpd->inserted = EINA_FALSE;
- efl_replace(&cpd->source, NULL);
- }
+ // Remove child from lookup tree if it exist before triggering anything further
+ pd->indexed = eina_rbtree_inline_remove(pd->indexed, EINA_RBTREE_GET(cpd),
+ EINA_RBTREE_CMP_NODE_CB(_children_indexed_cmp), NULL);
+ cpd->inserted = EINA_FALSE;
+ efl_replace(&cpd->source, NULL);
+ }
- // Update all index above this one if necessaryy
- eina_array_step_set(&mark, sizeof (Eina_Array), 8);
- _mark_greater((void*) pd->indexed, &mark, cev.index);
-
- // Correct index of the object stored that need to
- // There is no need to remove and reinsert them as their relative order will not change.
- EINA_ARRAY_ITER_NEXT(&mark, i, cpd, iterator)
- {
- if (description == EFL_MODEL_EVENT_CHILD_REMOVED) cpd->index--;
- else cpd->index++;
-
- efl_ref(cpd->self);
+ // Everything above the removed one is one closer
+ _mark_from((void*) pd->indexed, &mark, ev->index + 1);
+ EINA_ARRAY_ITER_NEXT(&mark, i, cpd, iterator)
+ {
+ cpd->index--;
+ efl_ref(cpd->self);
+ }
}
efl_event_callback_call(pd->self, description, &cev);
diff --git a/src/tests/efl/efl_test_composite_model.c b/src/tests/efl/efl_test_composite_model.c
index e10256b7e2..cf0ce5e7b2 100644
--- a/src/tests/efl/efl_test_composite_model.c
+++ b/src/tests/efl/efl_test_composite_model.c
@@ -589,12 +589,24 @@ _marked_get(Eo *child)
return b;
}
+static void
+_added_child_keep(void *data, const Efl_Event *ev)
+{
+ Efl_Model_Children_Event *cev = ev->info;
+ Eo **kept = data;
+
+ // Volatile children go once nobody holds them
+ *kept = efl_ref(cev->child);
+}
+
static Eina_Value
_insert_check(Eo *model, void *data EINA_UNUSED, const Eina_Value v)
{
Efl_Model_Children_Event ev = { 0 };
Eo *base = efl_ui_view_model_get(model);
Eo *kids[5] = { NULL };
+ Eo *sources[5] = { NULL };
+ Eo *row, *added = NULL;
unsigned int i, len;
Eo *c;
@@ -602,21 +614,40 @@ _insert_check(Eo *model, void *data EINA_UNUSED, const Eina_Value v)
{
ck_assert_int_lt(i, 5);
kids[i] = c;
+ sources[i] = efl_ui_view_model_get(c);
}
ck_assert_int_eq(len, 5);
efl_model_property_set(kids[2], "marked", eina_value_bool_new(EINA_TRUE));
ck_assert(_marked_get(kids[2]));
- ev.index = 0;
+ // A new row in the middle, announced the way a model that can insert does it
+ row = efl_add(EFL_GENERIC_MODEL_CLASS, base);
+ ev.index = 2;
+ ev.child = row;
+ efl_event_callback_add(model, EFL_MODEL_EVENT_CHILD_ADDED, _added_child_keep, &added);
efl_event_callback_call(base, EFL_MODEL_EVENT_CHILD_ADDED, &ev);
+ efl_event_callback_del(model, EFL_MODEL_EVENT_CHILD_ADDED, _added_child_keep, &added);
+ // The new row is the one at 2, unmarked, and is not the one that was there
+ ck_assert_ptr_ne(added, NULL);
+ ck_assert_ptr_ne(added, kids[2]);
+ ck_assert_ptr_eq(efl_ui_view_model_get(added), row);
+ ck_assert_int_eq(efl_composite_model_index_get(added), 2);
+ ck_assert(!_marked_get(added));
+
+ // The old 2 is 3 now, still its own row, and keeps its mark
ck_assert_int_eq(efl_composite_model_index_get(kids[2]), 3);
- // The old child 2 is now child 3 and keeps its mark, whatever now sits at 2 does not
+ ck_assert_ptr_eq(efl_ui_view_model_get(kids[2]), sources[2]);
ck_assert(_marked_get(kids[2]));
- ck_assert_int_eq(efl_composite_model_index_get(kids[1]), 2);
- ck_assert(!_marked_get(kids[1]));
+ // Those before are where they were, and those after are one further
+ ck_assert_int_eq(efl_composite_model_index_get(kids[1]), 1);
+ ck_assert(!_marked_get(kids[1]));
+ ck_assert_int_eq(efl_composite_model_index_get(kids[3]), 4);
+ ck_assert(!_marked_get(kids[3]));
+
+ efl_unref(added);
ecore_main_loop_quit();
return v;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.