tasn pushed a commit to branch master.

http://git.enlightenment.org/core/elementary.git/commit/?id=b4fca621509571623f3c5b25cc547cca699d09d5

commit b4fca621509571623f3c5b25cc547cca699d09d5
Author: Subodh Kumar <s7158.ku...@samsung.com>
Date:   Mon Dec 21 14:41:28 2015 +0000

    Entry: Add newline filter for single line entry
    
    Summary:
    Add newline filter
    
    Using the present filter infra
    a newline or paragraph separator filter
    is being added for single line entry.
    
    @fix
    
    Test Plan:
    Copy multiline text from
    and paste it to single line entry.
    
    it will fix T2660
    
    Reviewers: herdsman, tasn
    
    Subscribers: thiepha, DaveMDS
    
    Maniphest Tasks: T2660
    
    Differential Revision: https://phab.enlightenment.org/D3109
---
 src/lib/elm_entry.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/src/lib/elm_entry.c b/src/lib/elm_entry.c
index 700116c..fa28a37 100644
--- a/src/lib/elm_entry.c
+++ b/src/lib/elm_entry.c
@@ -2604,6 +2604,79 @@ _item_get(void *data,
    return o;
 }
 
+static Eina_Bool
+_entry_has_new_line(const char *text)
+{
+   if (!text) return EINA_FALSE;
+
+   while (*text)
+     {
+        if (!strncmp(text, "<br", 3) || !strncmp(text, "<ps", 3))
+          {
+             if (text[4] == '>' || ((text[4] == '/') && (text[5] == '>')))
+               {
+                  return EINA_TRUE;
+               }
+          }
+        text++;
+     }
+
+   return EINA_FALSE;
+}
+
+static char *
+_entry_remove_new_line(const char *text)
+{
+   Eina_Strbuf *str;
+   char *new_text;
+
+   if (!_entry_has_new_line(text)) return NULL;
+
+   str = eina_strbuf_new();
+   eina_strbuf_append(str, text);
+   eina_strbuf_replace_all(str, "<br>", "");
+   eina_strbuf_replace_all(str, "<br/>", "");
+   eina_strbuf_replace_all(str, "<ps>", "");
+   eina_strbuf_replace_all(str, "<ps/>", "");
+   new_text = eina_strbuf_string_steal(str);
+   eina_strbuf_free(str);
+   return new_text;
+}
+
+static void
+_entry_new_line_filter_init(Evas_Object *obj)
+{
+   const char *text;
+   char *text2 = NULL;
+
+   if (elm_entry_is_empty(obj)) return;
+
+   text = elm_entry_entry_get(obj);
+   text2 = _entry_remove_new_line(text);
+   if (text2)
+     {
+        elm_entry_entry_set(obj, text2);
+        free(text2);
+     }
+}
+
+static void
+_entry_new_line_filter_cb(void *data EINA_UNUSED,
+                          Evas_Object *entry EINA_UNUSED,
+                          char **text)
+{
+   char *old_text;
+
+   if (!*text) return;
+
+   old_text = *text;
+   *text = _entry_remove_new_line((const char*)*text);
+   if (*text)
+     free(old_text);
+   else
+     *text = old_text;
+}
+
 static void
 _markup_filter_cb(void *data,
                   Evas_Object *edje EINA_UNUSED,
@@ -3816,6 +3889,15 @@ _elm_entry_single_line_set(Eo *obj, Elm_Entry_Data *sd, 
Eina_Bool single_line)
    sd->line_wrap = ELM_WRAP_NONE;
    if (elm_entry_cnp_mode_get(obj) == ELM_CNP_MODE_MARKUP)
      elm_entry_cnp_mode_set(obj, ELM_CNP_MODE_NO_IMAGE);
+   if (sd->single_line)
+     {
+        _entry_new_line_filter_init(obj);
+        elm_entry_markup_filter_append(obj, _entry_new_line_filter_cb, NULL);
+     }
+   else
+     {
+        elm_entry_markup_filter_remove(obj, _entry_new_line_filter_cb, NULL);
+     }
    eo_do(obj, elm_obj_widget_theme_apply());
 
    if (sd->scroll)

-- 


Reply via email to