From fdde1ebe95091ded93ab542d4c5c8d09a9c405bf Mon Sep 17 00:00:00 2001 From: Subodh Kumar Date: Thu, 17 Dec 2015 11:54:35 +0000 Subject: [PATCH] Evas textblock: Use width of item format to position cursor. Summary: Use width of item format to position cursor. Sometimes it becomes very difficult to position cursor over item and selection becomes very difficult as we position the cursor once the input X coord reached end of the item, like one attached in the test plan. So this patch decides over 50% of item width for X coord reaches to position it at start or end. @ix Test Plan: Attached setup shows how difficult to position cursor at the end when clicked over item and selection is also very difficult. Consider such case in mobile device, its becomes impossible to position cursor at the end and selection is too much difficult. {F27036} Also added test cases in evas test suite Reviewers: herdsman, tasn Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D3390 Change-Id: I801bfd2e3754299b5268be9970eed9ae5b340935 --- src/lib/evas/canvas/evas_object_textblock.c | 10 +++++++++- src/tests/evas/evas_test_textblock.c | 14 +++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index 53f4f76..13169e1 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -11393,7 +11393,15 @@ _evas_textblock_cursor_coord_set(Evas_Textblock_Cursor *cur, Evas_Coord x, Evas_ { Evas_Object_Textblock_Format_Item *fi; fi = _ITEM_FORMAT(it); - cur->pos = fi->parent.text_pos; + /* Lets keep cur position half way for easy positioning */ + if (x > (ln->x + it->x + (it->adv / 2))) + { + cur->pos = fi->parent.text_pos + 1; + } + else + { + cur->pos = fi->parent.text_pos; + } cur->node = found_par->text_node; return EINA_TRUE; } diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c index ad6237d..090fd8e 100644 --- a/src/tests/evas/evas_test_textblock.c +++ b/src/tests/evas/evas_test_textblock.c @@ -1699,7 +1699,7 @@ END_TEST /* Testing items */ START_TEST(evas_textblock_items) { - Evas_Coord w, h, w2, h2, nw, nh, ih; + Evas_Coord x, y, w, h, w2, h2, nw, nh, ih; START_TB_TEST(); const char *buf = "This is an ."; @@ -1804,6 +1804,18 @@ START_TEST(evas_textblock_items) if (evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h)) fail_if((w != 64) || (h != 64)); + /* Test char coordinate for item at middle position of the item to decide cursor position, + * it means when char coordinate exceeds the half width of the item then only + * cursor position is changed. */ + buf = "."; + evas_object_textblock_text_markup_set(tb, buf); + evas_textblock_cursor_format_item_geometry_get(cur, &x, &y, &w, NULL); + evas_textblock_cursor_char_coord_set(cur, x + (w / 2) + 1, y); + fail_if(evas_textblock_cursor_pos_get(cur) != 1); + /* Test small increment in x and cursor position will be same */ + evas_textblock_cursor_char_coord_set(cur, x + 10, y); + fail_if(evas_textblock_cursor_pos_get(cur) != 0); + /* FIXME: Also verify x,y positions of the item. */ /* FIXME We need some item tests that involve line wrapping that make the -- 2.7.4