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
This commit is contained in:
Ali Alzyod 2020-01-02 07:25:35 +00:00 committed by Marcel Hollerbach
parent a95a509cfd
commit 41c7e1c908
2 changed files with 121 additions and 118 deletions

View File

@ -8524,7 +8524,7 @@ static void
_evas_object_textblock_text_markup_prepend(Eo *eo_obj,
Efl_Text_Cursor_Handle *cur, const char *text)
{
if (!cur) return;
if (!cur || !text || !*text) return;
Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
evas_object_async_block(obj);
TB_HEAD();
@ -8533,140 +8533,138 @@ _evas_object_textblock_text_markup_prepend(Eo *eo_obj,
* this should be done once, when markup_prepend finished */
o->pause_change = EINA_TRUE;
if (text)
char *s, *p;
char *tag_start, *tag_end, *esc_start, *esc_end;
tag_start = tag_end = esc_start = esc_end = NULL;
p = (char *)text;
s = p;
/* This loop goes through all of the mark up text until it finds format
* tags, escape sequences or the terminating NULL. When it finds either
* of those, it appends the text found up until that point to the textblock
* proccesses whatever found. It repeats itself until the terminating
* NULL is reached. */
for (;;)
{
char *s, *p;
char *tag_start, *tag_end, *esc_start, *esc_end;
tag_start = tag_end = esc_start = esc_end = NULL;
p = (char *)text;
s = p;
/* This loop goes through all of the mark up text until it finds format
* tags, escape sequences or the terminating NULL. When it finds either
* of those, it appends the text found up until that point to the textblock
* proccesses whatever found. It repeats itself until the terminating
* NULL is reached. */
for (;;)
size_t text_len;
/* If we got to the end of string or just finished/started tag
* or escape sequence handling. */
if ((*p == 0) ||
(tag_end) || (esc_end) ||
(tag_start) || (esc_start))
{
size_t text_len;
/* If we got to the end of string or just finished/started tag
* or escape sequence handling. */
if ((*p == 0) ||
(tag_end) || (esc_end) ||
(tag_start) || (esc_start))
if (tag_end)
{
if (tag_end)
{
/* If we reached to a tag ending, analyze the tag */
char *ttag;
size_t ttag_len = tag_end - tag_start;
/* If we reached to a tag ending, analyze the tag */
char *ttag;
size_t ttag_len = tag_end - tag_start;
ttag = malloc(ttag_len + 1);
if (ttag)
{
memcpy(ttag, tag_start, ttag_len);
ttag[ttag_len] = 0;
evas_textblock_cursor_format_prepend(cur, ttag);
free(ttag);
}
tag_start = tag_end = NULL;
}
else if (esc_end)
ttag = malloc(ttag_len + 1);
if (ttag)
{
_prepend_escaped_char(cur, esc_start, esc_end + 1);
esc_start = esc_end = NULL;
memcpy(ttag, tag_start, ttag_len);
ttag[ttag_len] = 0;
evas_textblock_cursor_format_prepend(cur, ttag);
free(ttag);
}
else if (*p == 0 && esc_start) /* escape start with no end, append it as text */
{
_prepend_text_run(cur, esc_start, p);
esc_start = esc_end = NULL;
s = NULL;
}
else if (*p == 0)
{
_prepend_text_run(cur, s, p);
s = NULL;
}
if (*p == 0)
break;
tag_start = tag_end = NULL;
}
if (*p == '<')
else if (esc_end)
{
if (esc_start) /* escape start with no end, append it as text */
{
_prepend_text_run(cur, esc_start, p);
esc_start = esc_end = NULL;
s = NULL;
}
if (!esc_start)
{
/* Append the text prior to this to the textblock and mark
* the start of the tag */
tag_start = p;
tag_end = NULL;
_prepend_text_run(cur, s, p);
s = NULL;
}
_prepend_escaped_char(cur, esc_start, esc_end + 1);
esc_start = esc_end = NULL;
}
else if (*p == '>')
else if (*p == 0 && esc_start) /* escape start with no end, append it as text */
{
if (tag_start)
{
tag_end = p + 1;
s = p + 1;
}
_prepend_text_run(cur, esc_start, p);
esc_start = esc_end = NULL;
s = NULL;
}
else if (*p == '&')
else if (*p == 0)
{
if (esc_start) /* escape start with no end, append it as text */
{
_prepend_text_run(cur, esc_start, p);
esc_start = esc_end = NULL;
s = NULL;
}
if (!tag_start)
{
/* Append the text prior to this to the textblock and mark
* the start of the escape sequence */
esc_start = p;
esc_end = NULL;
_prepend_text_run(cur, s, p);
s = NULL;
}
}
else if (*p == ';')
{
if (esc_start)
{
esc_end = p;
s = p + 1;
}
}
/* Unicode object replacement char */
else if (!strncmp(_REPLACEMENT_CHAR_UTF8, p,
text_len = strlen(_REPLACEMENT_CHAR_UTF8)) ||
!strncmp(_NEWLINE_UTF8, p,
text_len = strlen(_NEWLINE_UTF8)) ||
!strncmp(_TAB_UTF8, p,
text_len = strlen(_TAB_UTF8)) ||
!strncmp(_PARAGRAPH_SEPARATOR_UTF8, p,
text_len = strlen(_PARAGRAPH_SEPARATOR_UTF8)))
{
/*FIXME: currently just remove them, maybe do something
* fancier in the future, atm it breaks if this char
* is inside <> */
_prepend_text_run(cur, s, p);
/* it's also advanced later in this loop need +text_len
in total*/
p += text_len - 1;
s = p + 1; /* One after the end of the replacement char */
s = NULL;
}
p++;
if (*p == 0)
break;
}
if (*p == '<')
{
if (esc_start) /* escape start with no end, append it as text */
{
_prepend_text_run(cur, esc_start, p);
esc_start = esc_end = NULL;
s = NULL;
}
if (!esc_start)
{
/* Append the text prior to this to the textblock and mark
* the start of the tag */
tag_start = p;
tag_end = NULL;
_prepend_text_run(cur, s, p);
s = NULL;
}
}
else if (*p == '>')
{
if (tag_start)
{
tag_end = p + 1;
s = p + 1;
}
}
else if (*p == '&')
{
if (esc_start) /* escape start with no end, append it as text */
{
_prepend_text_run(cur, esc_start, p);
esc_start = esc_end = NULL;
s = NULL;
}
if (!tag_start)
{
/* Append the text prior to this to the textblock and mark
* the start of the escape sequence */
esc_start = p;
esc_end = NULL;
_prepend_text_run(cur, s, p);
s = NULL;
}
}
else if (*p == ';')
{
if (esc_start)
{
esc_end = p;
s = p + 1;
}
}
/* Unicode object replacement char */
else if (!strncmp(_REPLACEMENT_CHAR_UTF8, p,
text_len = strlen(_REPLACEMENT_CHAR_UTF8)) ||
!strncmp(_NEWLINE_UTF8, p,
text_len = strlen(_NEWLINE_UTF8)) ||
!strncmp(_TAB_UTF8, p,
text_len = strlen(_TAB_UTF8)) ||
!strncmp(_PARAGRAPH_SEPARATOR_UTF8, p,
text_len = strlen(_PARAGRAPH_SEPARATOR_UTF8)))
{
/*FIXME: currently just remove them, maybe do something
* fancier in the future, atm it breaks if this char
* is inside <> */
_prepend_text_run(cur, s, p);
/* it's also advanced later in this loop need +text_len
in total*/
p += text_len - 1;
s = p + 1; /* One after the end of the replacement char */
}
p++;
}
o->pause_change = EINA_FALSE;
efl_event_callback_call(cur->obj, EFL_CANVAS_TEXTBLOCK_EVENT_CHANGED, NULL);
_evas_textblock_changed(o, eo_obj);
}

View File

@ -4530,7 +4530,12 @@ EFL_START_TEST(efl_canvas_textblock_cursor)
efl_text_set(txt, "");
efl_text_set(txt, "");
efl_text_cursor_text_insert(cursor1, "aa");
ck_assert_int_eq(changed_emit, 3);
ck_assert_int_eq(changed_emit, 4);
efl_text_markup_set(txt, "Hello<br/>Word");
efl_text_markup_set(txt, "Hello<br/>Word");
efl_text_cursor_markup_insert(cursor1, "aa");
ck_assert_int_eq(changed_emit, 6);
efl_text_set(txt, "");
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)
ck_assert(!efl_text_cursor_move(cur_obj, EFL_TEXT_CURSOR_MOVE_TYPE_LAST));
ck_assert_int_eq(efl_text_cursor_position_get(cur_obj), 0);
ck_assert_int_eq(changed_emit, 4);
ck_assert_int_eq(changed_emit, 7);
efl_text_markup_set(txt, "Hello World<ps/>This is EFL<br/>Enlightenment");
ck_assert(efl_text_cursor_move(cur_obj, EFL_TEXT_CURSOR_MOVE_TYPE_CHAR_NEXT));