summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2014-08-04 11:01:51 +0100
committerTom Hacohen <tom@stosb.com>2014-08-04 11:01:51 +0100
commit104f04eda19395396116ba4c4c23b17f00ace2ae (patch)
treeff2a99cb8874bc0e5ca2c2dff06766608420bf92
parent8c677a1f0ea59a7403522d3252a3c886ed552b72 (diff)
downloadefl-104f04eda19395396116ba4c4c23b17f00ace2ae.tar.gz
Evas textblock: Correct word start/end moving at new line or line begins with spaces
Summary: Word start/end works incorrectly when it goes to new line or line begins with spaces. Ex: In elementary_test/Entry, place cursor at the end of line, press ctrl + right arrow keys: cursor moves to begin of next line. In this case, cursor should move to end of 1st word in next line. Ex2: In elementary_test/Entry, add some spaces to begin of 2nd line (" uses markup"), place cursor at the first word ("uses"), press ctrl + left arrow keys twice, cursor moves to begin of 2nd line. In this case, cursor should move to begin of last word in 1st line. This patch provides a fix by considerring next/previous text node to move cursor to correct place. @fix Reviewers: woohyun, raster, tasn Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1140
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c30
-rw-r--r--src/tests/evas/evas_test_textblock.c12
2 files changed, 41 insertions, 1 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 58cc4764c3..87d6664287 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -7349,7 +7349,23 @@ evas_textblock_cursor_word_start(Evas_Textblock_Cursor *cur)
for (i = cur->pos ; _is_white(text[i]) && BREAK_AFTER(i) ; i--)
{
- if (i == 0) break;
+ if (i == 0)
+ {
+ Evas_Object_Textblock_Node_Text *pnode;
+ pnode = _NODE_TEXT(EINA_INLIST_GET(cur->node)->prev);
+ if (pnode)
+ {
+ cur->node = pnode;
+ len = eina_ustrbuf_length_get(cur->node->unicode);
+ cur->pos = len - 1;
+ free(breaks);
+ return evas_textblock_cursor_word_start(cur);
+ }
+ else
+ {
+ break;
+ }
+ }
}
for ( ; i > 0 ; i--)
@@ -7390,6 +7406,18 @@ evas_textblock_cursor_word_end(Evas_Textblock_Cursor *cur)
}
for (i = cur->pos; text[i] && _is_white(text[i]) && (BREAK_AFTER(i)) ; i++);
+ if (i == len)
+ {
+ Evas_Object_Textblock_Node_Text *nnode;
+ nnode = _NODE_TEXT(EINA_INLIST_GET(cur->node)->next);
+ if (nnode)
+ {
+ cur->node = nnode;
+ cur->pos = 0;
+ free(breaks);
+ return evas_textblock_cursor_word_end(cur);
+ }
+ }
for ( ; text[i] ; i++)
{
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c
index a727b760f2..63ba40eda6 100644
--- a/src/tests/evas/evas_test_textblock.c
+++ b/src/tests/evas/evas_test_textblock.c
@@ -637,6 +637,18 @@ START_TEST(evas_textblock_cursor)
evas_textblock_cursor_word_end(cur);
ck_assert_int_eq(5, evas_textblock_cursor_pos_get(cur));
+
+ /* moving across paragraphs */
+ evas_object_textblock_text_markup_set(tb,
+ "test<ps/>"
+ " case");
+ evas_textblock_cursor_pos_set(cur, 4);
+ evas_textblock_cursor_word_end(cur);
+ ck_assert_int_eq(10, evas_textblock_cursor_pos_get(cur));
+
+ evas_textblock_cursor_pos_set(cur, 6);
+ evas_textblock_cursor_word_start(cur);
+ ck_assert_int_eq(0, evas_textblock_cursor_pos_get(cur));
}
/* Make sure coords are correct for ligatures */