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 2034bae96269b6bd6b0b70fe93bd01e2e3b0e1af
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 10 18:15:18 2026 -0600
elementary: select_model: a failed unselect of the old row rolls back
In single mode a select asks for the unselect of the row selected before
along with its own commit. When that select was cancelled before it
committed, the rollback unselected the new row but left last_model on
the row it had just taken back, and the previous row was not given the
selection back.
The rollback now gives the last selected row back to the previous row
when it is still a row and still selected (and to nobody otherwise),
unless a later selection replaced it. What it needs for that is
allocated before anything is stored, so that running out of memory
rejects the select instead of leaving the future without its data.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_select_model.c | 78 +++++++++++++++++++++----
src/tests/elementary/efl_ui_test_select_model.c | 69 ++++++++++++++++++++++
2 files changed, 137 insertions(+), 10 deletions(-)
diff --git a/src/lib/elementary/efl_ui_select_model.c b/src/lib/elementary/efl_ui_select_model.c
index 2112239f33..a4a9b216e0 100644
--- a/src/lib/elementary/efl_ui_select_model.c
+++ b/src/lib/elementary/efl_ui_select_model.c
@@ -329,19 +329,60 @@ _untangle_array(void *data EINA_UNUSED,
return va;
}
-static Eina_Value
-_untangle_error(void *data, Eina_Error err)
+// What a select that unselects the row selected before keeps to roll back with
+typedef struct
{
- Efl_Model *child = data;
- Eina_Future *f;
+ Eo *obj; // the row being selected
+ Eo *prev; // the row that was selected, which this one was to replace
+} Untangle;
- // We need to roll back the change, which means in this
- // case to unselect this child as this is the only case
- // where we could end up here.
+static Untangle *
+_untangle_new(Eo *obj, Eo *prev)
+{
+ Untangle *u = calloc(1, sizeof (Untangle));
+
+ if (!u) return NULL;
+ u->obj = efl_ref(obj);
+ u->prev = efl_ref(prev);
+ return u;
+}
+
+// We need to roll back the change, which means in this
+// case to unselect this child as this is the only case
+// where we could end up here. The row before stays the selected one, when it is still a
+// row and is still selected, as its unselect is what failed.
+static Eina_Value
+_untangle_rollback(Untangle *u, Eina_Error err)
+{
+ Eo *child = u->obj;
+ Efl_Ui_Select_Model_Data *pd = efl_data_scope_get(efl_parent_get(child),
+ EFL_UI_SELECT_MODEL_CLASS);
+ Eina_Future *f;
Eina_Error *error = calloc(1, sizeof (Eina_Error));
f = efl_model_property_set(efl_super(child, EFL_UI_SELECT_MODEL_CLASS),
"selected", eina_value_bool_new(EINA_FALSE));
+
+ // A later selection asked for in the meantime is the last one, not this one
+ if ((pd) && (pd->last_model == child))
+ {
+ Eo *keep = NULL;
+
+ if (u->prev && (efl_composite_model_index_get(u->prev) != 0xFFFFFFFF))
+ {
+ Eina_Value *selected;
+ Eina_Bool flag = EINA_FALSE;
+
+ selected = efl_model_property_get(efl_super(u->prev, EFL_UI_SELECT_MODEL_CLASS),
+ "selected");
+ eina_value_bool_get(selected, &flag);
+ eina_value_free(selected);
+ if (flag) keep = u->prev;
+ }
+ _efl_ui_select_model_apply_last_model(efl_parent_get(child), pd, keep);
+ }
+
+ if (!error) return eina_future_as_value(f);
// Once this is done, we need to repropagate the error
*error = err;
f = eina_future_then(f, _regenerate_error, error, NULL);
@@ -349,13 +390,21 @@ _untangle_error(void *data, Eina_Error err)
return eina_future_as_value(f);
}
+static Eina_Value
+_untangle_error(void *data, Eina_Error err)
+{
+ return _untangle_rollback(data, err);
+}
+
static void
_untangle_free(void *data,
const Eina_Future *dead_future EINA_UNUSED)
{
- Eo *obj = data;
+ Untangle *u = data;
- efl_unref(obj);
+ efl_unref(u->obj);
+ efl_unref(u->prev);
+ free(u);
}
static Eina_Iterator *
@@ -418,6 +467,7 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
Eina_Bool success;
Eina_Value *prev;
Eina_Future *chain;
+ Untangle *untangle = NULL;
// A row with no index left while a slice held it: it is not a row to select
if (efl_composite_model_index_get(obj) == 0xFFFFFFFF)
@@ -465,6 +515,14 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
single_selection = !!(pd->parent->selection == EFL_UI_SELECT_MODE_SINGLE);
+ // What the select keeps to roll back with, before anything is stored: no memory
+ // for it fails the select cleanly
+ if (single_selection && newflag && pd->parent->last_model)
+ {
+ untangle = _untangle_new(obj, pd->parent->last_model);
+ if (!untangle) return efl_loop_future_rejected(obj, ENOMEM);
+ }
+
// 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);
@@ -504,7 +562,7 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
chain = eina_future_then_easy(chain,
.success_type = EINA_VALUE_TYPE_ARRAY,
.success = _untangle_array,
- .data = ""
+ .data = ""
.error = _untangle_error,
.free = _untangle_free);
// This is the last one now, not once it commits: a selection asked for
diff --git a/src/tests/elementary/efl_ui_test_select_model.c b/src/tests/elementary/efl_ui_test_select_model.c
index 4382a5fb8e..d35fa2afaf 100644
--- a/src/tests/elementary/efl_ui_test_select_model.c
+++ b/src/tests/elementary/efl_ui_test_select_model.c
@@ -902,6 +902,74 @@ 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
+
void
efl_ui_test_select_model(TCase *tc)
{
@@ -920,4 +988,5 @@ efl_ui_test_select_model(TCase *tc)
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);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.