edje entry: return surrounding string until the start position of selection
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 25 Apr 2013 05:31:39 +0000 (14:31 +0900)
committerSungho Kwak <sungho1.kwak@samsung.com>
Tue, 11 Jun 2013 10:42:28 +0000 (19:42 +0900)
Change-Id: I2c5014e7d79b9c885147fa31b68613813e67a518

src/lib/edje_entry.c

index 46cd558..7813a44 100644 (file)
@@ -4976,6 +4976,7 @@ _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx __UNU
    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) ||
@@ -4990,14 +4991,45 @@ _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx __UNU
      {
         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;
 }