tyfuzz: better mock termio_take_selection()
+ fix leak + make the code more readable to me
This commit is contained in:
parent
e3a2d70e6d
commit
b7305bfc59
|
@ -322,7 +322,7 @@ termio_internal_get_selection(Termio *sd, size_t *lenp)
|
||||||
const char *s = NULL;
|
const char *s = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL);
|
||||||
if (sd->pty->selection.is_active)
|
if (sd->pty->selection.is_active)
|
||||||
{
|
{
|
||||||
start_x = sd->pty->selection.start.x;
|
start_x = sd->pty->selection.start.x;
|
||||||
|
@ -376,6 +376,7 @@ termio_internal_get_selection(Termio *sd, size_t *lenp)
|
||||||
|
|
||||||
termio_selection_get(sd, start_x, start_y, end_x, end_y, &sb, EINA_TRUE);
|
termio_selection_get(sd, start_x, start_y, end_x, end_y, &sb, EINA_TRUE);
|
||||||
len = sb.len;
|
len = sb.len;
|
||||||
|
|
||||||
s = eina_stringshare_add_length(ty_sb_steal_buf(&sb), len);
|
s = eina_stringshare_add_length(ty_sb_steal_buf(&sb), len);
|
||||||
ty_sb_free(&sb);
|
ty_sb_free(&sb);
|
||||||
}
|
}
|
||||||
|
@ -858,8 +859,12 @@ _sel_word(Termio *sd, int cx, int cy)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
cells = termpty_cellrow_get(sd->pty, y, &w);
|
cells = termpty_cellrow_get(sd->pty, y, &w);
|
||||||
if (!cells) goto end;
|
if (!cells)
|
||||||
if (x >= w) x = w - 1;
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (x >= w)
|
||||||
|
x = w - 1;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -901,7 +906,10 @@ _sel_word(Termio *sd, int cx, int cy)
|
||||||
{
|
{
|
||||||
y = cy;
|
y = cy;
|
||||||
cells = termpty_cellrow_get(sd->pty, y, &w);
|
cells = termpty_cellrow_get(sd->pty, y, &w);
|
||||||
if (!cells) goto end;
|
if (!cells)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
x = cx;
|
x = cx;
|
||||||
|
|
||||||
|
@ -925,11 +933,15 @@ _sel_word(Termio *sd, int cx, int cy)
|
||||||
}
|
}
|
||||||
if (!done)
|
if (!done)
|
||||||
{
|
{
|
||||||
if (!cells[w - 1].att.autowrapped) goto end;
|
if (!cells[w - 1].att.autowrapped)
|
||||||
|
goto end;
|
||||||
y++;
|
y++;
|
||||||
x = 0;
|
x = 0;
|
||||||
cells = termpty_cellrow_get(sd->pty, y, &w);
|
cells = termpty_cellrow_get(sd->pty, y, &w);
|
||||||
if (!cells) goto end;
|
if (!cells)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!done);
|
while (!done);
|
||||||
|
@ -938,6 +950,7 @@ _sel_word(Termio *sd, int cx, int cy)
|
||||||
|
|
||||||
sd->pty->selection.by_word = EINA_TRUE;
|
sd->pty->selection.by_word = EINA_TRUE;
|
||||||
sd->pty->selection.is_top_to_bottom = EINA_TRUE;
|
sd->pty->selection.is_top_to_bottom = EINA_TRUE;
|
||||||
|
|
||||||
_trim_sel_word(sd);
|
_trim_sel_word(sd);
|
||||||
|
|
||||||
termpty_backlog_unlock();
|
termpty_backlog_unlock();
|
||||||
|
@ -1639,15 +1652,23 @@ termio_internal_mouse_down(Termio *sd,
|
||||||
else if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
|
else if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
|
||||||
{
|
{
|
||||||
if (!sd->pty->selection.is_active && sd->didclick)
|
if (!sd->pty->selection.is_active && sd->didclick)
|
||||||
sd->pty->selection.is_active = EINA_TRUE;
|
{
|
||||||
|
sd->pty->selection.is_active = EINA_TRUE;
|
||||||
|
}
|
||||||
if (modifiers.shift && sd->pty->selection.is_active)
|
if (modifiers.shift && sd->pty->selection.is_active)
|
||||||
_sel_word_to(sd, cx, cy - sd->scroll, EINA_TRUE);
|
{
|
||||||
|
_sel_word_to(sd, cx, cy - sd->scroll, EINA_TRUE);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
_sel_word(sd, cx, cy - sd->scroll);
|
{
|
||||||
|
_sel_word(sd, cx, cy - sd->scroll);
|
||||||
|
}
|
||||||
if (sd->pty->selection.is_active)
|
if (sd->pty->selection.is_active)
|
||||||
{
|
{
|
||||||
if (!termio_take_selection(sd->self, ELM_SEL_TYPE_PRIMARY))
|
if (!termio_take_selection(sd->self, ELM_SEL_TYPE_PRIMARY))
|
||||||
termio_sel_set(sd, EINA_FALSE);
|
{
|
||||||
|
termio_sel_set(sd, EINA_FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sd->didclick = EINA_TRUE;
|
sd->didclick = EINA_TRUE;
|
||||||
_sel_fill_in_codepoints_array(sd);
|
_sel_fill_in_codepoints_array(sd);
|
||||||
|
|
|
@ -116,9 +116,8 @@ _tytest_modifiers_get(const Eina_Unicode *buf, Termio_Modifiers *m)
|
||||||
/**
|
/**
|
||||||
* FLAGS can be:
|
* FLAGS can be:
|
||||||
* - 0
|
* - 0
|
||||||
* - 1: SINGLE_CLICK
|
* - 1: DOUBLE_CLICK
|
||||||
* - 2: DOUBLE_CLICK
|
* - 2: TRIPLE_CLICK
|
||||||
* - 3: TRIPLE_CLICK
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -220,8 +219,13 @@ _handle_selection_is(Termpty *ty,
|
||||||
const Eina_Unicode *buf)
|
const Eina_Unicode *buf)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
Termio *sd = termio_get_from_obj(ty->obj);
|
Termio *sd;
|
||||||
const char *s = termio_internal_get_selection(sd, &len);
|
const char *s;
|
||||||
|
|
||||||
|
assert(ty->selection.is_active);
|
||||||
|
|
||||||
|
sd = termio_get_from_obj(ty->obj);
|
||||||
|
s = termio_internal_get_selection(sd, &len);
|
||||||
|
|
||||||
assert(s != NULL && "no selection");
|
assert(s != NULL && "no selection");
|
||||||
|
|
||||||
|
@ -238,6 +242,7 @@ _handle_selection_is(Termpty *ty,
|
||||||
}
|
}
|
||||||
buf++;
|
buf++;
|
||||||
}
|
}
|
||||||
|
eina_stringshare_del(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -200,9 +200,20 @@ termio_block_activate(Evas_Object *obj EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
termio_take_selection(Evas_Object *obj EINA_UNUSED,
|
termio_take_selection(Evas_Object *obj,
|
||||||
Elm_Sel_Type type EINA_UNUSED)
|
Elm_Sel_Type type EINA_UNUSED)
|
||||||
{
|
{
|
||||||
|
Termio *sd;
|
||||||
|
const char *s;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
sd = termio_get_from_obj(obj);
|
||||||
|
s = termio_internal_get_selection(sd, &len);
|
||||||
|
if (s)
|
||||||
|
{
|
||||||
|
eina_stringshare_del(s);
|
||||||
|
return EINA_TRUE;
|
||||||
|
}
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue