summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Hirt <daniel.hirt@samsung.com>2016-07-03 13:57:22 +0000
committerDaniel Hirt <daniel.hirt@samsung.com>2016-07-03 14:39:45 +0000
commit06fd1566eaa01b236fbaabd2ce3536606890805e (patch)
tree982e9fcae1cea2a70506521c84a787ba195aa7a9 /src
parent5fa3815e01d7d16f04d13a6ebd28e7c5d2d9dba9 (diff)
Canvas text cursor: fix bug after code port
Fixes T4005. Also, unified repeated code and added a test for multiple cursors.
Diffstat (limited to 'src')
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c71
-rw-r--r--src/tests/evas/evas_test_textblock.c29
2 files changed, 63 insertions, 37 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index e0130b7..cd78e82 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -9682,6 +9682,31 @@ _evas_textblock_cursors_set_node(Efl_Canvas_Text_Data *o,
9682 } 9682 }
9683} 9683}
9684 9684
9685static inline void
9686_cursor_update_offset(Efl_Canvas_Text_Cursor_Data *cur, Efl_Canvas_Text_Data *o,
9687 const Evas_Object_Textblock_Node_Text *n, size_t start, int offset)
9688{
9689 if ((n == cur->node) &&
9690 (cur->pos > start))
9691 {
9692 if ((offset < 0) && (cur->pos <= (size_t) (-1 * offset)))
9693 {
9694 cur->pos = 0;
9695 }
9696 else
9697 {
9698 cur->pos += offset;
9699 }
9700 cur->changed = EINA_TRUE;
9701 }
9702 else if (!cur->node)
9703 {
9704 cur->node = o->text_nodes;
9705 cur->pos = 0;
9706 cur->changed = EINA_TRUE;
9707 }
9708}
9709
9685/** 9710/**
9686 * @internal 9711 * @internal
9687 * Update the offset of all the cursors after cur. 9712 * Update the offset of all the cursors after cur.
@@ -9697,50 +9722,22 @@ _evas_textblock_cursors_update_offset(const Efl_Canvas_Text_Cursor_Data *cur,
9697 size_t start, int offset) 9722 size_t start, int offset)
9698{ 9723{
9699 Eina_List *l; 9724 Eina_List *l;
9700 Efl_Canvas_Text_Cursor *data_obj; 9725 Efl_Canvas_Text_Cursor *ocur_obj;
9726 Efl_Canvas_Text_Cursor_Data *ocur;
9701 Efl_Canvas_Text_Data *o = eo_data_scope_get(cur->obj, MY_CLASS); 9727 Efl_Canvas_Text_Data *o = eo_data_scope_get(cur->obj, MY_CLASS);
9702 9728
9703 Efl_Canvas_Text_Cursor_Data *ocur = eo_data_scope_get(o->cursor, EFL_CANVAS_TEXT_CURSOR_CLASS); 9729 ocur = eo_data_scope_get(o->cursor, EFL_CANVAS_TEXT_CURSOR_CLASS);
9704 if (cur != ocur) 9730 if (cur != ocur)
9705 { 9731 {
9706 if ((n == cur->node) && 9732 _cursor_update_offset(ocur, o, n, start, offset);
9707 (cur->pos > start))
9708 {
9709 if ((offset < 0) && (cur->pos <= (size_t) (-1 * offset)))
9710 {
9711 ocur->pos = 0;
9712 }
9713 else
9714 {
9715 ocur->pos += offset;
9716 }
9717 ocur->changed = EINA_TRUE;
9718 }
9719 } 9733 }
9720 EINA_LIST_FOREACH(o->cursors, l, data_obj) 9734
9735 EINA_LIST_FOREACH(o->cursors, l, ocur_obj)
9721 { 9736 {
9722 Efl_Canvas_Text_Cursor_Data *data = eo_data_scope_get(data_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); 9737 ocur = eo_data_scope_get(ocur_obj, EFL_CANVAS_TEXT_CURSOR_CLASS);
9723 if (data != cur) 9738 if (ocur != cur)
9724 { 9739 {
9725 if ((n == data->node) && 9740 _cursor_update_offset(ocur, o, n, start, offset);
9726 (data->pos > start))
9727 {
9728 if ((offset < 0) && (data->pos <= (size_t) (-1 * offset)))
9729 {
9730 data->pos = 0;
9731 }
9732 else
9733 {
9734 data->pos += offset;
9735 }
9736 data->changed = EINA_TRUE;
9737 }
9738 else if (!data->node)
9739 {
9740 data->node = o->text_nodes;
9741 data->pos = 0;
9742 data->changed = EINA_TRUE;
9743 }
9744 } 9741 }
9745 } 9742 }
9746} 9743}
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c
index 9d9ee2e..381c938 100644
--- a/src/tests/evas/evas_test_textblock.c
+++ b/src/tests/evas/evas_test_textblock.c
@@ -943,6 +943,35 @@ START_TEST(evas_textblock_cursor)
943 ck_assert_int_eq(pos, 44); 943 ck_assert_int_eq(pos, 44);
944 } 944 }
945 945
946 {
947 /* Test multiple cursors:
948 * Deleting characters should "pull" all the cursors positioned *after*
949 * the deleted position, and "push" on insertion.
950 * Testing with one additional cursor will suffice. */
951 int j, pos;
952 Evas_Textblock_Cursor *cur2;
953
954 cur2 = evas_object_textblock_cursor_new(tb);
955 evas_object_textblock_text_markup_set(tb, "Hello world");
956 evas_textblock_cursor_pos_set(cur2, 0);
957 evas_textblock_cursor_pos_set(cur, 5);
958 for (j = 5; j >= 0; j--)
959 {
960 pos = evas_textblock_cursor_pos_get(cur);
961 ck_assert_int_eq(pos, j);
962 evas_textblock_cursor_char_delete(cur2);
963 }
964 evas_object_textblock_text_markup_set(tb, "Hello world");
965 evas_textblock_cursor_pos_set(cur2, 0);
966 evas_textblock_cursor_pos_set(cur, 5);
967 for (j = 5; j <= 10; j++)
968 {
969 pos = evas_textblock_cursor_pos_get(cur);
970 ck_assert_int_eq(pos, j);
971 evas_textblock_cursor_text_append(cur2, "a");
972 }
973 evas_textblock_cursor_free(cur2);
974 }
946 END_TB_TEST(); 975 END_TB_TEST();
947} 976}
948END_TEST 977END_TEST