forked from enlightenment/efl
Canvas text cursor: fix bug after code port
Fixes T4005. Also, unified repeated code and added a test for multiple cursors.
This commit is contained in:
parent
5fa3815e01
commit
06fd1566ea
|
@ -9682,6 +9682,31 @@ _evas_textblock_cursors_set_node(Efl_Canvas_Text_Data *o,
|
|||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
_cursor_update_offset(Efl_Canvas_Text_Cursor_Data *cur, Efl_Canvas_Text_Data *o,
|
||||
const Evas_Object_Textblock_Node_Text *n, size_t start, int offset)
|
||||
{
|
||||
if ((n == cur->node) &&
|
||||
(cur->pos > start))
|
||||
{
|
||||
if ((offset < 0) && (cur->pos <= (size_t) (-1 * offset)))
|
||||
{
|
||||
cur->pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cur->pos += offset;
|
||||
}
|
||||
cur->changed = EINA_TRUE;
|
||||
}
|
||||
else if (!cur->node)
|
||||
{
|
||||
cur->node = o->text_nodes;
|
||||
cur->pos = 0;
|
||||
cur->changed = EINA_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Update the offset of all the cursors after cur.
|
||||
|
@ -9697,50 +9722,22 @@ _evas_textblock_cursors_update_offset(const Efl_Canvas_Text_Cursor_Data *cur,
|
|||
size_t start, int offset)
|
||||
{
|
||||
Eina_List *l;
|
||||
Efl_Canvas_Text_Cursor *data_obj;
|
||||
Efl_Canvas_Text_Cursor *ocur_obj;
|
||||
Efl_Canvas_Text_Cursor_Data *ocur;
|
||||
Efl_Canvas_Text_Data *o = eo_data_scope_get(cur->obj, MY_CLASS);
|
||||
|
||||
Efl_Canvas_Text_Cursor_Data *ocur = eo_data_scope_get(o->cursor, EFL_CANVAS_TEXT_CURSOR_CLASS);
|
||||
ocur = eo_data_scope_get(o->cursor, EFL_CANVAS_TEXT_CURSOR_CLASS);
|
||||
if (cur != ocur)
|
||||
{
|
||||
if ((n == cur->node) &&
|
||||
(cur->pos > start))
|
||||
{
|
||||
if ((offset < 0) && (cur->pos <= (size_t) (-1 * offset)))
|
||||
{
|
||||
ocur->pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ocur->pos += offset;
|
||||
}
|
||||
ocur->changed = EINA_TRUE;
|
||||
}
|
||||
_cursor_update_offset(ocur, o, n, start, offset);
|
||||
}
|
||||
EINA_LIST_FOREACH(o->cursors, l, data_obj)
|
||||
|
||||
EINA_LIST_FOREACH(o->cursors, l, ocur_obj)
|
||||
{
|
||||
Efl_Canvas_Text_Cursor_Data *data = eo_data_scope_get(data_obj, EFL_CANVAS_TEXT_CURSOR_CLASS);
|
||||
if (data != cur)
|
||||
ocur = eo_data_scope_get(ocur_obj, EFL_CANVAS_TEXT_CURSOR_CLASS);
|
||||
if (ocur != cur)
|
||||
{
|
||||
if ((n == data->node) &&
|
||||
(data->pos > start))
|
||||
{
|
||||
if ((offset < 0) && (data->pos <= (size_t) (-1 * offset)))
|
||||
{
|
||||
data->pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->pos += offset;
|
||||
}
|
||||
data->changed = EINA_TRUE;
|
||||
}
|
||||
else if (!data->node)
|
||||
{
|
||||
data->node = o->text_nodes;
|
||||
data->pos = 0;
|
||||
data->changed = EINA_TRUE;
|
||||
}
|
||||
_cursor_update_offset(ocur, o, n, start, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -943,6 +943,35 @@ START_TEST(evas_textblock_cursor)
|
|||
ck_assert_int_eq(pos, 44);
|
||||
}
|
||||
|
||||
{
|
||||
/* Test multiple cursors:
|
||||
* Deleting characters should "pull" all the cursors positioned *after*
|
||||
* the deleted position, and "push" on insertion.
|
||||
* Testing with one additional cursor will suffice. */
|
||||
int j, pos;
|
||||
Evas_Textblock_Cursor *cur2;
|
||||
|
||||
cur2 = evas_object_textblock_cursor_new(tb);
|
||||
evas_object_textblock_text_markup_set(tb, "Hello world");
|
||||
evas_textblock_cursor_pos_set(cur2, 0);
|
||||
evas_textblock_cursor_pos_set(cur, 5);
|
||||
for (j = 5; j >= 0; j--)
|
||||
{
|
||||
pos = evas_textblock_cursor_pos_get(cur);
|
||||
ck_assert_int_eq(pos, j);
|
||||
evas_textblock_cursor_char_delete(cur2);
|
||||
}
|
||||
evas_object_textblock_text_markup_set(tb, "Hello world");
|
||||
evas_textblock_cursor_pos_set(cur2, 0);
|
||||
evas_textblock_cursor_pos_set(cur, 5);
|
||||
for (j = 5; j <= 10; j++)
|
||||
{
|
||||
pos = evas_textblock_cursor_pos_get(cur);
|
||||
ck_assert_int_eq(pos, j);
|
||||
evas_textblock_cursor_text_append(cur2, "a");
|
||||
}
|
||||
evas_textblock_cursor_free(cur2);
|
||||
}
|
||||
END_TB_TEST();
|
||||
}
|
||||
END_TEST
|
||||
|
|
Loading…
Reference in New Issue