termio: allow to clear selection

This commit is contained in:
Boris Faure 2023-08-21 16:21:04 +02:00
parent e53fe0b624
commit e9253fb3cc
Signed by: borisfaure
GPG Key ID: EAA9CD729F522998
1 changed files with 26 additions and 18 deletions

View File

@ -1029,26 +1029,34 @@ _termio_set_selection_text(Termio *sd, Elm_Sel_Type type, const char *text)
EINA_SAFETY_ON_NULL_RETURN(sd);
text = eina_stringshare_add(text);
sd->have_sel = EINA_FALSE;
sd->reset_sel = EINA_FALSE;
sd->set_sel_at = ecore_time_get(); // hack
sd->sel_type = type;
res = elm_cnp_selection_set(sd->win, type,
ELM_SEL_FORMAT_TEXT,
text,
eina_stringshare_strlen(text));
if (!res)
if (text[0] != '\0')
{
ERR("Unable to set selection data '%s' of type %d", text, type);
text = eina_stringshare_add(text);
sd->have_sel = EINA_FALSE;
sd->reset_sel = EINA_FALSE;
sd->set_sel_at = ecore_time_get(); // hack
sd->sel_type = type;
res = elm_cnp_selection_set(sd->win, type,
ELM_SEL_FORMAT_TEXT,
text,
eina_stringshare_strlen(text));
if (!res)
{
ERR("Unable to set selection data '%s'(%d) of type %d",
text, eina_stringshare_strlen(text), type);
}
elm_cnp_selection_loss_callback_set(sd->win, type,
_lost_selection, sd->self);
sd->have_sel = EINA_TRUE;
eina_stringshare_del(sd->sel_str);
sd->sel_str = eina_stringshare_add(text);
}
else
{
elm_object_cnp_selection_clear(sd->win, type);
}
elm_cnp_selection_loss_callback_set(sd->win, type,
_lost_selection, sd->self);
sd->have_sel = EINA_TRUE;
eina_stringshare_del(sd->sel_str);
sd->sel_str = eina_stringshare_add(text);
}
void