summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorabdulleh Ghujeh <a.ghujeh@samsung.com>2020-10-20 19:20:27 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-10-20 19:20:28 +0900
commitd6a6dd54a13bfe079ae97eb016dd902e5dec5e60 (patch)
tree86fdc32e6a731f61e47e7273e217d830449b1719
parent3274390f7324b561739bdf2b620c939b6e0508fd (diff)
efl.ui.text : Fixing cursor movement using keyboard arrows/mouse click
Summary: if we have an emoji or a cluster combining multiple Unicode inside ui textbox, we can move the cursor inside the emoji/cluster using keyboard arrows/mouse click. so we should use cluster movement instead of character movement (same as entry). {F3868931} this should resolve T8666 Test Plan: #define EFL_EO_API_SUPPORT 1 #define EFL_BETA_API_SUPPORT 1 #include <Efl_Ui.h> static void _gui_quit_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) { efl_exit(0); } static void _gui_setup() { Eo *win, *box; win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(), efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC), efl_text_set(efl_added, "Hello World"), efl_ui_win_autodel_set(efl_added, EINA_TRUE)); // when the user clicks "close" on a window there is a request to delete efl_event_callback_add(win, EFL_UI_WIN_EVENT_DELETE_REQUEST, _gui_quit_cb, NULL); box = efl_add(EFL_UI_BOX_CLASS, win, efl_content_set(win, efl_added), efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(360, 240))); efl_add(EFL_UI_TEXTBOX_CLASS, box, efl_gfx_hint_weight_set(efl_added, 1.0, 1.0), efl_gfx_hint_align_set(efl_added, 1.0, 1.0), efl_text_markup_set(efl_added, "A&#x262a;&#xfe0f;"), efl_pack(box, efl_added)); } EAPI_MAIN void efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) { _gui_setup(); } EFL_MAIN() Reviewers: ali.alzyod, zmike, woohyun, bu5hm4n Reviewed By: ali.alzyod, woohyun Subscribers: zmike, cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8666 Differential Revision: https://phab.enlightenment.org/D11745
-rw-r--r--src/lib/elementary/efl_ui_internal_text_interactive.c12
-rw-r--r--src/tests/elementary/efl_ui_test_text.c42
2 files changed, 48 insertions, 6 deletions
diff --git a/src/lib/elementary/efl_ui_internal_text_interactive.c b/src/lib/elementary/efl_ui_internal_text_interactive.c
index f40ea261c4..d2220c451c 100644
--- a/src/lib/elementary/efl_ui_internal_text_interactive.c
+++ b/src/lib/elementary/efl_ui_internal_text_interactive.c
@@ -1251,7 +1251,7 @@ _key_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void
1251#endif 1251#endif
1252 if (efl_text_interactive_have_selection_get(obj)) 1252 if (efl_text_interactive_have_selection_get(obj))
1253 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 1253 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1254 if (efl_text_cursor_object_move(cur,EFL_TEXT_CURSOR_MOVE_TYPE_CHARACTER_PREVIOUS)) 1254 if (efl_text_cursor_object_move(cur,EFL_TEXT_CURSOR_MOVE_TYPE_CLUSTER_PREVIOUS))
1255 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 1255 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1256 1256
1257 _key_down_sel_post(obj, cur, en, shift); 1257 _key_down_sel_post(obj, cur, en, shift);
@@ -1270,7 +1270,7 @@ _key_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void
1270#endif 1270#endif
1271 if (efl_text_interactive_have_selection_get(obj)) 1271 if (efl_text_interactive_have_selection_get(obj))
1272 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 1272 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1273 if (efl_text_cursor_object_move(cur, EFL_TEXT_CURSOR_MOVE_TYPE_CHARACTER_NEXT)) 1273 if (efl_text_cursor_object_move(cur, EFL_TEXT_CURSOR_MOVE_TYPE_CLUSTER_NEXT))
1274 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 1274 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1275 1275
1276 _key_down_sel_post(obj, cur, en, shift); 1276 _key_down_sel_post(obj, cur, en, shift);
@@ -1551,7 +1551,7 @@ end:
1551} 1551}
1552 1552
1553static void 1553static void
1554_cursor_char_coord_set(Efl_Canvas_Textblock *obj, Efl_Text_Cursor_Object *cur, Evas_Coord canvasx, Evas_Coord canvasy, Evas_Coord *_cx, Evas_Coord *_cy) 1554_cursor_cluster_coord_set(Efl_Canvas_Textblock *obj, Efl_Text_Cursor_Object *cur, Evas_Coord canvasx, Evas_Coord canvasy, Evas_Coord *_cx, Evas_Coord *_cy)
1555{ 1555{
1556 Evas_Coord cx, cy; 1556 Evas_Coord cx, cy;
1557 Evas_Coord x, y, lh = 0, cly = 0; 1557 Evas_Coord x, y, lh = 0, cly = 0;
@@ -1582,7 +1582,7 @@ _cursor_char_coord_set(Efl_Canvas_Textblock *obj, Efl_Text_Cursor_Object *cur, E
1582 efl_del(line_cur); 1582 efl_del(line_cur);
1583 /* No need to check return value if not able to set the char coord Textblock 1583 /* No need to check return value if not able to set the char coord Textblock
1584 * will take care */ 1584 * will take care */
1585 efl_text_cursor_object_char_coord_set(cur, EINA_POSITION2D(cx, cy)); 1585 efl_text_cursor_object_cluster_coord_set(cur, EINA_POSITION2D(cx, cy));
1586 if (_cx) *_cx = cx; 1586 if (_cx) *_cx = cx;
1587 if (_cy) *_cy = cy; 1587 if (_cy) *_cy = cy;
1588} 1588}
@@ -1676,7 +1676,7 @@ _mouse_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EIN
1676 goto end; 1676 goto end;
1677 } 1677 }
1678 } 1678 }
1679 _cursor_char_coord_set(obj, cur, ev->canvas.x, ev->canvas.y, &cx, &cy); 1679 _cursor_cluster_coord_set(obj, cur, ev->canvas.x, ev->canvas.y, &cx, &cy);
1680 1680
1681 if (dosel) 1681 if (dosel)
1682 { 1682 {
@@ -1721,7 +1721,7 @@ _mouse_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void
1721 } 1721 }
1722#endif 1722#endif
1723 1723
1724 _cursor_char_coord_set(obj, cur, ev->canvas.x, ev->canvas.y, &cx, &cy); 1724 _cursor_cluster_coord_set(obj, cur, ev->canvas.x, ev->canvas.y, &cx, &cy);
1725 1725
1726 if (en->select_allow) 1726 if (en->select_allow)
1727 { 1727 {
diff --git a/src/tests/elementary/efl_ui_test_text.c b/src/tests/elementary/efl_ui_test_text.c
index ad876c6bcd..93a8a82669 100644
--- a/src/tests/elementary/efl_ui_test_text.c
+++ b/src/tests/elementary/efl_ui_test_text.c
@@ -483,6 +483,47 @@ EFL_START_TEST(text_multiline_singleline_cursor_pos)
483} 483}
484EFL_END_TEST 484EFL_END_TEST
485 485
486EFL_START_TEST(text_keyboard_mouse_cluster_cursor_movement)
487{
488 Eo *txt;
489 Eo *cursor;
490 Eo *win = win_add();
491 Evas *e;
492 Eina_Rect rc, rc2;
493
494 txt = efl_add(EFL_UI_TEXTBOX_CLASS, win);
495
496 efl_gfx_entity_size_set(win, EINA_SIZE2D(300, 300));
497 efl_gfx_entity_size_set(txt, EINA_SIZE2D(300, 300));
498 efl_ui_textbox_scrollable_set(txt, EINA_TRUE);
499 get_me_to_those_events(txt);
500
501 efl_text_markup_set(txt, "A\u1100\u1161\u11AA");
502 cursor = efl_text_interactive_main_cursor_get(txt);
503 efl_text_cursor_object_position_set(cursor, 1);
504
505 e = evas_object_evas_get(txt);
506 efl_ui_focus_util_focus(txt);
507 evas_event_feed_key_down(e, "Right", "Right", "Right", "Right", time(NULL), NULL);
508
509 ck_assert_int_eq(4, efl_text_cursor_object_position_get(cursor));
510
511 efl_text_cursor_object_position_set(cursor, 1);
512 efl_text_cursor_object_move(cursor, EFL_TEXT_CURSOR_MOVE_TYPE_CHARACTER_NEXT);
513 efl_text_cursor_object_move(cursor, EFL_TEXT_CURSOR_MOVE_TYPE_CHARACTER_NEXT);
514 rc = efl_text_cursor_object_content_geometry_get(cursor);
515 rc2 = efl_ui_scrollable_viewport_geometry_get(txt);
516
517 efl_text_cursor_object_position_set(cursor, 0);
518 click_object_at(win, rc2.x + rc.x + (rc.w/2), rc2.y + rc.y + (rc.h/2));
519
520 ck_assert_int_eq(4, efl_text_cursor_object_position_get(cursor));
521
522 efl_del(txt);
523 efl_del(win);
524}
525EFL_END_TEST
526
486void efl_ui_test_text(TCase *tc) 527void efl_ui_test_text(TCase *tc)
487{ 528{
488 tcase_add_test(tc, text_cnp); 529 tcase_add_test(tc, text_cnp);
@@ -497,4 +538,5 @@ void efl_ui_test_text(TCase *tc)
497 tcase_add_test(tc, text_singleline_cursor_movement); 538 tcase_add_test(tc, text_singleline_cursor_movement);
498 tcase_add_test(tc, text_multiline_singleline_cursor_pos); 539 tcase_add_test(tc, text_multiline_singleline_cursor_pos);
499 tcase_add_test(tc, text_on_startup); 540 tcase_add_test(tc, text_on_startup);
541 tcase_add_test(tc, text_keyboard_mouse_cluster_cursor_movement);
500} 542}