From 3eb79d3c3d582a6feba4ca90655c172bc42abc01 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 14 May 2013 09:33:19 +0900 Subject: [PATCH] Edje entry: return surrounding string until the start position of selection --- ChangeLog | 4 ++++ NEWS | 2 +- src/lib/edje/edje_entry.c | 40 +++++++++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2eeeb05fb..540922d8ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-05-14 Jihoon Kim + + * Edje entry: return surrounding string until the start position of selection + 2013-05-13 Thiep Ha * Edje: Added selection handlers to entry. diff --git a/NEWS b/NEWS index f2782a48c6..3a623aecd1 100644 --- a/NEWS +++ b/NEWS @@ -268,4 +268,4 @@ Fixes: * Evas: Don't try blend on gl backened if the render option is COPY * Evas text: Fixed line size calculation when using multiple fonts. * Evas: Fix crash if app use native surface in wrong engine. - + * Edje entry: return surrounding string until the start position of selection diff --git a/src/lib/edje/edje_entry.c b/src/lib/edje/edje_entry.c index ed3bf69d70..67458acc0b 100644 --- a/src/lib/edje/edje_entry.c +++ b/src/lib/edje/edje_entry.c @@ -4042,6 +4042,7 @@ _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx EINA_ Entry *en = NULL; const char *str; char *plain_text; + Eina_Strbuf *buf = NULL; if (!rp) return EINA_FALSE; if ((rp->type != EDJE_RP_TYPE_TEXT) || @@ -4056,14 +4057,45 @@ _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx EINA_ { str = _edje_entry_text_get(rp); if (str) - plain_text = evas_textblock_text_markup_to_utf8(NULL, str); + { + plain_text = evas_textblock_text_markup_to_utf8(NULL, str); + + if (plain_text) + { + if (en->have_selection) + { + buf = eina_strbuf_new(); + + if (en->sel_start) + eina_strbuf_append_n(buf, plain_text, evas_textblock_cursor_pos_get(en->sel_start)); + else + eina_strbuf_append(buf, plain_text); + + *text = strdup(eina_strbuf_string_get(buf)); + eina_strbuf_free(buf); + } + else + *text = strdup(plain_text); + + free(plain_text); + plain_text = NULL; + } + else + *text = strdup(""); + } else - plain_text = strdup(""); - *text = plain_text; + *text = strdup(""); } if (cursor_pos) - *cursor_pos = evas_textblock_cursor_pos_get(en->cursor); + { + if (en->have_selection && en->sel_start) + *cursor_pos = evas_textblock_cursor_pos_get(en->sel_start); + else if (en->cursor) + *cursor_pos = evas_textblock_cursor_pos_get(en->cursor); + else + *cursor_pos = 0; + } return EINA_TRUE; }