Canvas text: fix line_jump_by logic
authorDaniel Hirt <hirt.danny@gmail.com>
Fri, 7 Sep 2018 09:34:37 +0000 (12:34 +0300)
committerYeongjong Lee <yj34.lee@samsung.com>
Thu, 8 Nov 2018 06:40:49 +0000 (15:40 +0900)
Some cases of line_jump_by did not emit "cursor,changed" when it should
have.

@fix

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

index 4ea0143..f54bdcf 100644 (file)
@@ -10496,11 +10496,19 @@ _efl_canvas_text_efl_text_cursor_cursor_line_jump_by(Eo *eo_obj EINA_UNUSED, Efl
 {
    ASYNC_BLOCK;
    int ln;
-
-   ln = evas_textblock_cursor_line_geometry_get(cur, NULL, NULL, NULL, NULL) + by;
    Evas_Coord cx, cw;
    Evas_Coord lx, ly, lw, lh;
    int last;
+   Evas_Object_Textblock_Node_Text *pnode;
+   size_t ppos;
+
+
+   ln = evas_textblock_cursor_line_geometry_get(cur, NULL, NULL, NULL, NULL) + by;
+
+   if (!cur) return;
+
+   pnode = cur->node;
+   ppos = cur->pos;
 
    evas_textblock_cursor_geometry_get(cur, &cx, NULL, &cw, NULL, NULL, EVAS_TEXTBLOCK_CURSOR_UNDER);
    cx += (cw / 2);
@@ -10510,33 +10518,40 @@ _efl_canvas_text_efl_text_cursor_cursor_line_jump_by(Eo *eo_obj EINA_UNUSED, Efl
    if (ln < 0)
      {
         evas_textblock_cursor_paragraph_first(cur);
-        return;
      }
-   if (ln > last)
+
+   else if (ln > last)
      {
         evas_textblock_cursor_paragraph_last(cur);
-        return;
      }
 
-   if (!evas_object_textblock_line_number_geometry_get(cur->obj, ln, &lx, &ly, &lw, &lh))
-     return;
-   if (evas_textblock_cursor_char_coord_set(cur, cx, ly + (lh / 2)))
-     return;
-   evas_textblock_cursor_line_set(cur, ln);
-   if (cx < (lx + (lw / 2)))
-     {
-        if (ln == last) evas_textblock_cursor_paragraph_last(cur);
-        evas_textblock_cursor_line_char_first(cur);
-     }
    else
      {
-        if (ln == last)
-          evas_textblock_cursor_paragraph_last(cur);
-        else
-          evas_textblock_cursor_line_char_last(cur);
+        if (evas_object_textblock_line_number_geometry_get(cur->obj,
+                 ln, &lx, &ly, &lw, &lh) &&
+              (!evas_textblock_cursor_char_coord_set(cur, cx, ly + (lh / 2))))
+          {
+             evas_textblock_cursor_line_set(cur, ln);
+             if (cx < (lx + (lw / 2)))
+               {
+                  if (ln == last) evas_textblock_cursor_paragraph_last(cur);
+                  evas_textblock_cursor_line_char_first(cur);
+               }
+             else
+               {
+                  if (ln == last)
+                     evas_textblock_cursor_paragraph_last(cur);
+                  else
+                     evas_textblock_cursor_line_char_last(cur);
+               }
+          }
      }
 
-   efl_event_callback_legacy_call(eo_obj, EFL_CANVAS_TEXT_EVENT_CURSOR_CHANGED, NULL);
+   if ((pnode != cur->node) || (ppos != cur->pos))
+     {
+        efl_event_callback_legacy_call(eo_obj,
+              EFL_CANVAS_TEXT_EVENT_CURSOR_CHANGED, NULL);
+     }
 }
 
 EAPI int
index c794fce..62b3812 100644 (file)
@@ -4559,7 +4559,7 @@ EFL_START_TEST(efl_canvas_text_simple)
 }
 EFL_END_TEST
 
-EFL_START_TEST(efl_canvas_text_cursor)
+EFL_START_TEST(efl_text)
 {
    START_TB_TEST();
 
@@ -4592,6 +4592,26 @@ EFL_START_TEST(efl_canvas_text_cursor)
 }
 EFL_END_TEST
 
+EFL_START_TEST(efl_canvas_text_cursor)
+{
+   START_EFL_CANVAS_TEXT_TEST();
+   int pos;
+
+   const char *buf = "abcdefghij";
+   efl_text_set(txt, buf);
+   fail_if(strcmp(efl_text_get(txt), buf));
+
+   efl_text_cursor_line_jump_by(txt, cur, -1);
+   pos = efl_text_cursor_position_get(txt, cur);
+   ck_assert_int_eq(pos, 0);
+   efl_text_cursor_line_jump_by(txt, cur, 1);
+   pos = efl_text_cursor_position_get(txt, cur);
+   ck_assert_int_eq(pos, 10);
+
+   END_EFL_CANVAS_TEXT_TEST();
+}
+EFL_END_TEST
+
 void evas_test_textblock(TCase *tc)
 {
    tcase_add_test(tc, evas_textblock_simple);
@@ -4621,6 +4641,7 @@ void evas_test_textblock(TCase *tc)
    tcase_add_test(tc, evas_textblock_text_iface);
    tcase_add_test(tc, evas_textblock_annotation);
    tcase_add_test(tc, efl_canvas_text_simple);
+   tcase_add_test(tc, efl_text);
    tcase_add_test(tc, efl_canvas_text_cursor);
 }