evas_textblock: prevent updating cursor unless they are ready during markup_set
authorAli <ali198724@gmail.com>
Thu, 26 Mar 2020 05:49:02 +0000 (14:49 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Thu, 26 Mar 2020 21:04:32 +0000 (06:04 +0900)
Summary:
During Markup_set at text block level, we will not update the cursors, unless their status is updated and ready.

This can cause serious issues, especially if a cursor also depends on another cursor for some calculations, (like the segfault happening in TextBox T8637)

Reviewers: woohyun, bu5hm4n, zmike

Reviewed By: woohyun

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Maniphest Tasks: T8637

Differential Revision: https://phab.enlightenment.org/D11598

src/lib/evas/canvas/evas_object_textblock.c
src/tests/elementary/efl_ui_test_text.c

index 882f112..6d896f8 100644 (file)
@@ -636,6 +636,8 @@ static void evas_object_textblock_coords_recalc(Evas_Object *eo_obj,
                                                 void *type_private_data);
 static void _canvas_text_format_changed(Eo *eo_obj, Efl_Canvas_Textblock_Data *o);
 
+static void _evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur,
+                                                   Eina_Bool emit_change);
 static const Evas_Object_Func object_func =
 {
    /* methods (compulsory) */
@@ -8998,10 +9000,14 @@ _evas_object_textblock_text_markup_set(Eo *eo_obj, Efl_Canvas_Textblock_Data *o,
         Eina_List *l;
         Efl_Text_Cursor_Handle *cur;
 
-        evas_textblock_cursor_paragraph_first(o->cursor);
+        /*update all cursors positions first, without emitting change*/
+        EINA_LIST_FOREACH(o->cursors, l, cur)
+          {
+             _evas_textblock_cursor_paragraph_first(cur, EINA_FALSE);
+          }
+        /*emitting change event for all cursors, after all of them are ready*/
         EINA_LIST_FOREACH(o->cursors, l, cur)
           {
-             evas_textblock_cursor_paragraph_first(cur);
              _evas_textblock_cursor_object_changed(cur);
           }
 
@@ -10287,8 +10293,8 @@ found:
    _evas_textblock_changed(o, eo_obj);
 }
 
-EAPI void
-evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur)
+static void
+_evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur, Eina_Bool emit_change)
 {
    if (!cur) return;
    Evas_Object_Protected_Data *obj = efl_data_scope_get(cur->obj, EFL_CANVAS_OBJECT_CLASS);
@@ -10296,7 +10302,14 @@ evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur)
    Efl_Canvas_Textblock_Data *o = efl_data_scope_get(cur->obj, MY_CLASS);
    cur->node = o->text_nodes;
    cur->pos = 0;
-   _evas_textblock_cursor_object_changed(cur);
+   if (emit_change)
+     _evas_textblock_cursor_object_changed(cur);
+}
+
+EAPI void
+evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur)
+{
+   _evas_textblock_cursor_paragraph_first(cur, EINA_TRUE);
 }
 
 EAPI void
index 63df679..63df0e7 100644 (file)
@@ -52,7 +52,7 @@ _stop_event_soon(void *data EINA_UNUSED, const Efl_Event *ev)
 
 EFL_START_TEST(text_all_select_all_unselect)
 {
-   Eo *txt;
+   Eo *txt, *txt2;
    Eo *win = win_add();
 
    int i_have_selection = 0, i_selection = 0;
@@ -116,8 +116,12 @@ EFL_START_TEST(text_all_select_all_unselect)
    efl_text_interactive_all_unselect(txt);
    ck_assert_int_eq(i_have_selection, 2);
 
+   //cursor selection change on efl_markup_set
+   txt2 = efl_add(EFL_UI_TEXTBOX_CLASS, win);
+   efl_text_markup_set(txt2, "<ps>");
 
    efl_del(txt);
+   efl_del(txt2);
    efl_del(win);
 }
 EFL_END_TEST