Evas textblock: fix evas_textblock_cursor_line_set 32/66932/2
authorDaniel Hirt <daniel.hirt@samsung.com>
Mon, 7 Dec 2015 15:23:24 +0000 (17:23 +0200)
committerYoungbok Shin <youngb.shin@samsung.com>
Mon, 25 Apr 2016 04:25:10 +0000 (21:25 -0700)
The line_set function should set the cursor to the first logical
position in the line. We can't use the first text position of the
first item in the line, due to BiDi considerations (the line may be
reordered). I've split evas_textblock_cursor_line_char_first to avoid
code duplication, as it already handles these cases.

@fix

Change-Id: I8f493bc62b53b57e170829d01ad8cf43dc716642

src/lib/evas/canvas/evas_object_textblock.c
src/tests/evas/evas_test_textblock.c

index 402604ba8aceb77672959228aa2bc5e670759895..a78389d363210426c9571e5740dcb91cef5a06b9 100644 (file)
@@ -8624,6 +8624,33 @@ evas_textblock_cursor_paragraph_char_last(Evas_Textblock_Cursor *cur)
 
 }
 
+static void
+_cursor_line_first_char_get(Evas_Object_Textblock_Line *ln,
+                            Evas_Textblock_Cursor *cur,
+                            Evas_Textblock_Data *o)
+{
+   if (ln->items)
+     {
+        Evas_Object_Textblock_Item *it;
+        size_t pos;
+        pos = ln->items->text_pos;
+        EINA_INLIST_FOREACH(EINA_INLIST_GET(ln->items)->next, it)
+          {
+             if (it->text_pos < pos)
+               {
+                  pos = it->text_pos;
+               }
+          }
+        cur->pos = pos;
+        cur->node = ln->items->text_node;
+     }
+   else
+     {
+        cur->pos = 0;
+        cur->node = o->text_nodes;
+     }
+}
+
 EAPI void
 evas_textblock_cursor_line_char_first(Evas_Textblock_Cursor *cur)
 {
@@ -8638,26 +8665,12 @@ evas_textblock_cursor_line_char_first(Evas_Textblock_Cursor *cur)
 
    _relayout_if_needed(cur->obj, o);
 
+   /* We don't actually need 'it', but it needs to be non NULL */
    _find_layout_item_match(cur, &ln, &it);
 
    if (!ln) return;
-   if (ln->items)
-     {
-        Evas_Object_Textblock_Item *i;
-        it = ln->items;
-        EINA_INLIST_FOREACH(ln->items, i)
-          {
-             if (it->text_pos > i->text_pos)
-               {
-                  it = i;
-               }
-          }
-     }
-   if (it)
-     {
-        cur->pos = it->text_pos;
-        cur->node = it->text_node;
-     }
+
+   _cursor_line_first_char_get(ln, cur, o);
 }
 
 EAPI void
@@ -9204,7 +9217,6 @@ EAPI Eina_Bool
 evas_textblock_cursor_line_set(Evas_Textblock_Cursor *cur, int line)
 {
    Evas_Object_Textblock_Line *ln;
-   Evas_Object_Textblock_Item *it;
 
    if (!cur) return EINA_FALSE;
    Evas_Object_Protected_Data *obj = eo_data_scope_get(cur->obj, EVAS_OBJECT_CLASS);
@@ -9216,17 +9228,9 @@ evas_textblock_cursor_line_set(Evas_Textblock_Cursor *cur, int line)
 
    ln = _find_layout_line_num(cur->obj, line);
    if (!ln) return EINA_FALSE;
-   it = (Evas_Object_Textblock_Item *)ln->items;
-   if (it)
-     {
-        cur->pos = it->text_pos;
-        cur->node = it->text_node;
-     }
-   else
-     {
-        cur->pos = 0;
-        cur->node = o->text_nodes;
-     }
+
+   _cursor_line_first_char_get(ln, cur, o);
+
    return EINA_TRUE;
 }
 
index bf151c63f9d0e1e08d6b6dcd637854df93de30fc..acd76cf6622d77e5efb8752c8d06cdc851b6fb07 100644 (file)
@@ -924,6 +924,25 @@ START_TEST(evas_textblock_cursor)
 #endif
      }
 
+   /* Line set with BiDi text */
+     {
+        size_t pos;
+
+        evas_object_textblock_text_markup_set(tb,
+              "שלום עולם hello world<ps>"
+              "שלום עולם hello world<ps>"
+              "hello world שלום עולם");
+        evas_textblock_cursor_line_set(cur, 0);
+        pos = evas_textblock_cursor_pos_get(cur);
+        ck_assert_int_eq(pos, 0);
+        evas_textblock_cursor_line_set(cur, 1);
+        pos = evas_textblock_cursor_pos_get(cur);
+        ck_assert_int_eq(pos, 22);
+        evas_textblock_cursor_line_set(cur, 2);
+        pos = evas_textblock_cursor_pos_get(cur);
+        ck_assert_int_eq(pos, 44);
+     }
+
    END_TB_TEST();
 }
 END_TEST