summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2020-01-02 07:25:35 +0000
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2020-01-02 12:16:11 +0100
commit41c7e1c908772bd8f4ec266c661faabeea357ec6 (patch)
tree6831bac6ce3e2589d9305615cc6b469b007d141f
parenta95a509cfd9dbccefe360efa3ff4b717b24adb3e (diff)
efl.text.cursor: emit events CANVAS_TEXTBLOCK_CHANGED when insert text using efl_text_cursor_markup_insert
efl.text.cursor: emit events CANVAS_TEXTBLOCK_CHANGED when insert text using efl_text_cursor_markup_insert Differential Revision: https://phab.enlightenment.org/D10985
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c226
-rw-r--r--src/tests/evas/evas_test_textblock.c9
2 files changed, 119 insertions, 116 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 2347961759..817008c889 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -8524,7 +8524,7 @@ static void
8524_evas_object_textblock_text_markup_prepend(Eo *eo_obj, 8524_evas_object_textblock_text_markup_prepend(Eo *eo_obj,
8525 Efl_Text_Cursor_Handle *cur, const char *text) 8525 Efl_Text_Cursor_Handle *cur, const char *text)
8526{ 8526{
8527 if (!cur) return; 8527 if (!cur || !text || !*text) return;
8528 Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); 8528 Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
8529 evas_object_async_block(obj); 8529 evas_object_async_block(obj);
8530 TB_HEAD(); 8530 TB_HEAD();
@@ -8533,140 +8533,138 @@ _evas_object_textblock_text_markup_prepend(Eo *eo_obj,
8533 * this should be done once, when markup_prepend finished */ 8533 * this should be done once, when markup_prepend finished */
8534 o->pause_change = EINA_TRUE; 8534 o->pause_change = EINA_TRUE;
8535 8535
8536 if (text) 8536 char *s, *p;
8537 { 8537 char *tag_start, *tag_end, *esc_start, *esc_end;
8538 char *s, *p; 8538
8539 char *tag_start, *tag_end, *esc_start, *esc_end; 8539 tag_start = tag_end = esc_start = esc_end = NULL;
8540 8540 p = (char *)text;
8541 tag_start = tag_end = esc_start = esc_end = NULL; 8541 s = p;
8542 p = (char *)text; 8542 /* This loop goes through all of the mark up text until it finds format
8543 s = p; 8543 * tags, escape sequences or the terminating NULL. When it finds either
8544 /* This loop goes through all of the mark up text until it finds format 8544 * of those, it appends the text found up until that point to the textblock
8545 * tags, escape sequences or the terminating NULL. When it finds either 8545 * proccesses whatever found. It repeats itself until the terminating
8546 * of those, it appends the text found up until that point to the textblock 8546 * NULL is reached. */
8547 * proccesses whatever found. It repeats itself until the terminating 8547 for (;;)
8548 * NULL is reached. */ 8548 {
8549 for (;;) 8549 size_t text_len;
8550 { 8550 /* If we got to the end of string or just finished/started tag
8551 size_t text_len; 8551 * or escape sequence handling. */
8552 /* If we got to the end of string or just finished/started tag 8552 if ((*p == 0) ||
8553 * or escape sequence handling. */ 8553 (tag_end) || (esc_end) ||
8554 if ((*p == 0) || 8554 (tag_start) || (esc_start))
8555 (tag_end) || (esc_end) || 8555 {
8556 (tag_start) || (esc_start)) 8556 if (tag_end)
8557 { 8557 {
8558 if (tag_end) 8558 /* If we reached to a tag ending, analyze the tag */
8559 { 8559 char *ttag;
8560 /* If we reached to a tag ending, analyze the tag */ 8560 size_t ttag_len = tag_end - tag_start;
8561 char *ttag;
8562 size_t ttag_len = tag_end - tag_start;
8563 8561
8564 8562
8565 ttag = malloc(ttag_len + 1); 8563 ttag = malloc(ttag_len + 1);
8566 if (ttag) 8564 if (ttag)
8567 {
8568 memcpy(ttag, tag_start, ttag_len);
8569 ttag[ttag_len] = 0;
8570 evas_textblock_cursor_format_prepend(cur, ttag);
8571 free(ttag);
8572 }
8573 tag_start = tag_end = NULL;
8574 }
8575 else if (esc_end)
8576 {
8577 _prepend_escaped_char(cur, esc_start, esc_end + 1);
8578 esc_start = esc_end = NULL;
8579 }
8580 else if (*p == 0 && esc_start) /* escape start with no end, append it as text */
8581 {
8582 _prepend_text_run(cur, esc_start, p);
8583 esc_start = esc_end = NULL;
8584 s = NULL;
8585 }
8586 else if (*p == 0)
8587 { 8565 {
8588 _prepend_text_run(cur, s, p); 8566 memcpy(ttag, tag_start, ttag_len);
8589 s = NULL; 8567 ttag[ttag_len] = 0;
8568 evas_textblock_cursor_format_prepend(cur, ttag);
8569 free(ttag);
8590 } 8570 }
8591 if (*p == 0) 8571 tag_start = tag_end = NULL;
8592 break;
8593 } 8572 }
8594 if (*p == '<') 8573 else if (esc_end)
8595 { 8574 {
8596 if (esc_start) /* escape start with no end, append it as text */ 8575 _prepend_escaped_char(cur, esc_start, esc_end + 1);
8597 { 8576 esc_start = esc_end = NULL;
8598 _prepend_text_run(cur, esc_start, p);
8599 esc_start = esc_end = NULL;
8600 s = NULL;
8601 }
8602 if (!esc_start)
8603 {
8604 /* Append the text prior to this to the textblock and mark
8605 * the start of the tag */
8606 tag_start = p;
8607 tag_end = NULL;
8608 _prepend_text_run(cur, s, p);
8609 s = NULL;
8610 }
8611 } 8577 }
8612 else if (*p == '>') 8578 else if (*p == 0 && esc_start) /* escape start with no end, append it as text */
8613 { 8579 {
8614 if (tag_start) 8580 _prepend_text_run(cur, esc_start, p);
8615 { 8581 esc_start = esc_end = NULL;
8616 tag_end = p + 1; 8582 s = NULL;
8617 s = p + 1;
8618 }
8619 } 8583 }
8620 else if (*p == '&') 8584 else if (*p == 0)
8621 { 8585 {
8622 if (esc_start) /* escape start with no end, append it as text */ 8586 _prepend_text_run(cur, s, p);
8623 { 8587 s = NULL;
8624 _prepend_text_run(cur, esc_start, p);
8625 esc_start = esc_end = NULL;
8626 s = NULL;
8627 }
8628 if (!tag_start)
8629 {
8630 /* Append the text prior to this to the textblock and mark
8631 * the start of the escape sequence */
8632 esc_start = p;
8633 esc_end = NULL;
8634 _prepend_text_run(cur, s, p);
8635 s = NULL;
8636 }
8637 } 8588 }
8638 else if (*p == ';') 8589 if (*p == 0)
8590 break;
8591 }
8592 if (*p == '<')
8593 {
8594 if (esc_start) /* escape start with no end, append it as text */
8639 { 8595 {
8640 if (esc_start) 8596 _prepend_text_run(cur, esc_start, p);
8641 { 8597 esc_start = esc_end = NULL;
8642 esc_end = p; 8598 s = NULL;
8643 s = p + 1;
8644 }
8645 } 8599 }
8646 /* Unicode object replacement char */ 8600 if (!esc_start)
8647 else if (!strncmp(_REPLACEMENT_CHAR_UTF8, p,
8648 text_len = strlen(_REPLACEMENT_CHAR_UTF8)) ||
8649 !strncmp(_NEWLINE_UTF8, p,
8650 text_len = strlen(_NEWLINE_UTF8)) ||
8651 !strncmp(_TAB_UTF8, p,
8652 text_len = strlen(_TAB_UTF8)) ||
8653 !strncmp(_PARAGRAPH_SEPARATOR_UTF8, p,
8654 text_len = strlen(_PARAGRAPH_SEPARATOR_UTF8)))
8655 { 8601 {
8656 /*FIXME: currently just remove them, maybe do something 8602 /* Append the text prior to this to the textblock and mark
8657 * fancier in the future, atm it breaks if this char 8603 * the start of the tag */
8658 * is inside <> */ 8604 tag_start = p;
8605 tag_end = NULL;
8659 _prepend_text_run(cur, s, p); 8606 _prepend_text_run(cur, s, p);
8660 /* it's also advanced later in this loop need +text_len 8607 s = NULL;
8661 in total*/
8662 p += text_len - 1;
8663 s = p + 1; /* One after the end of the replacement char */
8664 } 8608 }
8665 p++;
8666 } 8609 }
8610 else if (*p == '>')
8611 {
8612 if (tag_start)
8613 {
8614 tag_end = p + 1;
8615 s = p + 1;
8616 }
8617 }
8618 else if (*p == '&')
8619 {
8620 if (esc_start) /* escape start with no end, append it as text */
8621 {
8622 _prepend_text_run(cur, esc_start, p);
8623 esc_start = esc_end = NULL;
8624 s = NULL;
8625 }
8626 if (!tag_start)
8627 {
8628 /* Append the text prior to this to the textblock and mark
8629 * the start of the escape sequence */
8630 esc_start = p;
8631 esc_end = NULL;
8632 _prepend_text_run(cur, s, p);
8633 s = NULL;
8634 }
8635 }
8636 else if (*p == ';')
8637 {
8638 if (esc_start)
8639 {
8640 esc_end = p;
8641 s = p + 1;
8642 }
8643 }
8644 /* Unicode object replacement char */
8645 else if (!strncmp(_REPLACEMENT_CHAR_UTF8, p,
8646 text_len = strlen(_REPLACEMENT_CHAR_UTF8)) ||
8647 !strncmp(_NEWLINE_UTF8, p,
8648 text_len = strlen(_NEWLINE_UTF8)) ||
8649 !strncmp(_TAB_UTF8, p,
8650 text_len = strlen(_TAB_UTF8)) ||
8651 !strncmp(_PARAGRAPH_SEPARATOR_UTF8, p,
8652 text_len = strlen(_PARAGRAPH_SEPARATOR_UTF8)))
8653 {
8654 /*FIXME: currently just remove them, maybe do something
8655 * fancier in the future, atm it breaks if this char
8656 * is inside <> */
8657 _prepend_text_run(cur, s, p);
8658 /* it's also advanced later in this loop need +text_len
8659 in total*/
8660 p += text_len - 1;
8661 s = p + 1; /* One after the end of the replacement char */
8662 }
8663 p++;
8667 } 8664 }
8668 8665
8669 o->pause_change = EINA_FALSE; 8666 o->pause_change = EINA_FALSE;
8667 efl_event_callback_call(cur->obj, EFL_CANVAS_TEXTBLOCK_EVENT_CHANGED, NULL);
8670 _evas_textblock_changed(o, eo_obj); 8668 _evas_textblock_changed(o, eo_obj);
8671} 8669}
8672 8670
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c
index ef830e8507..261c12145c 100644
--- a/src/tests/evas/evas_test_textblock.c
+++ b/src/tests/evas/evas_test_textblock.c
@@ -4530,7 +4530,12 @@ EFL_START_TEST(efl_canvas_textblock_cursor)
4530 efl_text_set(txt, ""); 4530 efl_text_set(txt, "");
4531 efl_text_set(txt, ""); 4531 efl_text_set(txt, "");
4532 efl_text_cursor_text_insert(cursor1, "aa"); 4532 efl_text_cursor_text_insert(cursor1, "aa");
4533 ck_assert_int_eq(changed_emit, 3); 4533 ck_assert_int_eq(changed_emit, 4);
4534
4535 efl_text_markup_set(txt, "Hello<br/>Word");
4536 efl_text_markup_set(txt, "Hello<br/>Word");
4537 efl_text_cursor_markup_insert(cursor1, "aa");
4538 ck_assert_int_eq(changed_emit, 6);
4534 4539
4535 efl_text_set(txt, ""); 4540 efl_text_set(txt, "");
4536 ck_assert(!efl_text_cursor_move(cur_obj, EFL_TEXT_CURSOR_MOVE_TYPE_CHAR_NEXT)); 4541 ck_assert(!efl_text_cursor_move(cur_obj, EFL_TEXT_CURSOR_MOVE_TYPE_CHAR_NEXT));
@@ -4549,7 +4554,7 @@ EFL_START_TEST(efl_canvas_textblock_cursor)
4549 ck_assert(!efl_text_cursor_move(cur_obj, EFL_TEXT_CURSOR_MOVE_TYPE_LAST)); 4554 ck_assert(!efl_text_cursor_move(cur_obj, EFL_TEXT_CURSOR_MOVE_TYPE_LAST));
4550 ck_assert_int_eq(efl_text_cursor_position_get(cur_obj), 0); 4555 ck_assert_int_eq(efl_text_cursor_position_get(cur_obj), 0);
4551 4556
4552 ck_assert_int_eq(changed_emit, 4); 4557 ck_assert_int_eq(changed_emit, 7);
4553 4558
4554 efl_text_markup_set(txt, "Hello World<ps/>This is EFL<br/>Enlightenment"); 4559 efl_text_markup_set(txt, "Hello World<ps/>This is EFL<br/>Enlightenment");
4555 ck_assert(efl_text_cursor_move(cur_obj, EFL_TEXT_CURSOR_MOVE_TYPE_CHAR_NEXT)); 4560 ck_assert(efl_text_cursor_move(cur_obj, EFL_TEXT_CURSOR_MOVE_TYPE_CHAR_NEXT));