From e9253fb3cc9f16351ea5c71bdb257daf96d33794 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 21 Aug 2023 16:21:04 +0200 Subject: [PATCH] termio: allow to clear selection --- src/bin/termio.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/bin/termio.c b/src/bin/termio.c index 7f076eec..d4540393 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -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