[evolution] Reply to selection in text-highlight part loses white-spaces



commit 586ab6e32a64e18b78607b3300e82181ee3b11ff
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jun 27 10:17:31 2014 +0200

    Reply to selection in text-highlight part loses white-spaces
    
    text-highlight module encloses the generated text into <pre/> tags,
    thus the preview panel shows white-spaces correctly, but once
    a reply is done to a selected text the returned HTML portion had
    missing <pre/> tags, which led to lose of the white-spaces in
    the generated content (in UI), while the white-spaces were there
    in the raw HTML code. Enclosing selected HTML portion into <pre/>
    tags in case the original text is also enclosed it them fixes it.

 e-util/e-web-view.c |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index abe33b9..e17a180 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -2620,6 +2620,27 @@ e_web_view_update_actions (EWebView *web_view)
        g_signal_emit (web_view, signals[UPDATE_ACTIONS], 0);
 }
 
+static gboolean
+element_is_in_pre_tag (WebKitDOMNode *node)
+{
+       WebKitDOMElement *element;
+
+       if (!node)
+               return FALSE;
+
+       while (element = webkit_dom_node_get_parent_element (node), element) {
+               node = WEBKIT_DOM_NODE (element);
+
+               if (WEBKIT_DOM_IS_HTML_PRE_ELEMENT (element)) {
+                       return TRUE;
+               } else if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (element)) {
+                       break;
+               }
+       }
+
+       return FALSE;
+}
+
 static gchar *
 web_view_get_frame_selection_html (WebKitDOMElement *iframe)
 {
@@ -2640,6 +2661,9 @@ web_view_get_frame_selection_html (WebKitDOMElement *iframe)
 
                range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
                if (range != NULL) {
+                       gchar *inner_html;
+                       WebKitDOMNode *node;
+
                        fragment = webkit_dom_range_clone_contents (
                                range, NULL);
 
@@ -2649,8 +2673,16 @@ web_view_get_frame_selection_html (WebKitDOMElement *iframe)
                                WEBKIT_DOM_NODE (element),
                                WEBKIT_DOM_NODE (fragment), NULL);
 
-                       return webkit_dom_html_element_get_inner_html (
+                       inner_html = webkit_dom_html_element_get_inner_html (
                                WEBKIT_DOM_HTML_ELEMENT (element));
+                       node = webkit_dom_range_get_start_container (range, NULL);
+                       if (element_is_in_pre_tag (node)) {
+                               gchar *tmp = inner_html;
+                               inner_html = g_strconcat ("<pre>", tmp, "</pre>", NULL);
+                               g_free (tmp);
+                       }
+
+                       return inner_html;
                }
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]