[evolution/gnome-3-18] Composer - Last empty block in pasted content could be inaccessible



commit e499d5964d6ebfdfc9e227e1809428dc1db7448b
Author: Tomas Popela <tpopela redhat com>
Date:   Wed Dec 2 14:33:35 2015 +0100

    Composer - Last empty block in pasted content could be inaccessible
    
    There were just quote characters (that are non-selectable) as the elementary BR
    was removed while wrapping. Also simplify a code a little bit by switching to id
    instead of class while marking first or last BR element.

 e-util/e-html-editor-selection.c |   18 +++++++++++++-
 e-util/e-html-editor-view.c      |   48 ++++++++++++--------------------------
 2 files changed, 32 insertions(+), 34 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 8bc800c..efab355 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -6407,11 +6407,27 @@ wrap_lines (EHTMLEditorSelection *selection,
                start_node = node;
        } else {
                WebKitDOMElement *selection_start_marker, *selection_end_marker;
-               WebKitDOMNode *start_point = NULL;
+               WebKitDOMNode *start_point = NULL, *first_child;
 
                if (!webkit_dom_node_has_child_nodes (block))
                        return WEBKIT_DOM_ELEMENT (block);
 
+               /* Avoid wrapping when the block contains just the BR element alone
+                * or with selection markers. */
+               if ((first_child = webkit_dom_node_get_first_child (block)) &&
+                    WEBKIT_DOM_IS_HTMLBR_ELEMENT (first_child)) {
+                       WebKitDOMNode *next_sibling;
+
+                       if ((next_sibling = webkit_dom_node_get_next_sibling (first_child))) {
+                              if (e_html_editor_node_is_selection_position_node (next_sibling) &&
+                                  (next_sibling = webkit_dom_node_get_next_sibling (next_sibling)) &&
+                                  e_html_editor_node_is_selection_position_node (next_sibling) &&
+                                  !webkit_dom_node_get_next_sibling (next_sibling))
+                                       return WEBKIT_DOM_ELEMENT (block);
+                       } else
+                               return WEBKIT_DOM_ELEMENT (block);
+               }
+
                block_clone = webkit_dom_node_clone_node (block, TRUE);
                /* When we wrap, we are wrapping just the text after caret, text
                 * before the caret is already wrapped, so unwrap the text after
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index a312288..b136902 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -6581,8 +6581,8 @@ quote_plain_text_recursive (WebKitDOMDocument *document,
                                goto next_node;
                        }
                        goto not_br;
-               } else if (element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-first-br") ||
-                          element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-last-br")) {
+               } else if (element_has_id (WEBKIT_DOM_ELEMENT (node), "-x-evo-first-br") ||
+                          element_has_id (WEBKIT_DOM_ELEMENT (node), "-x-evo-last-br")) {
                        quote_br_node (node, quote_level);
                        node = next_sibling;
                        skip_node = TRUE;
@@ -7324,7 +7324,7 @@ parse_html_into_paragraphs (EHTMLEditorView *view,
                                        document,
                                        blockquote,
                                        block,
-                                       "<br class=\"-x-evo-first-br\">");
+                                       "<br id=\"-x-evo-first-br\">");
                        } else
                                preserve_next_line = FALSE;
                } else if (first_element && !citation_was_first_element) {
@@ -7333,7 +7333,7 @@ parse_html_into_paragraphs (EHTMLEditorView *view,
                                document,
                                blockquote,
                                block,
-                               "<br class=\"-x-evo-first-br\">");
+                               "<br id=\"-x-evo-first-br\">");
                } else
                        preserve_next_line = FALSE;
  next:
@@ -7362,9 +7362,9 @@ parse_html_into_paragraphs (EHTMLEditorView *view,
                                child = webkit_dom_node_get_first_child (child);
                                if (child && WEBKIT_DOM_IS_HTMLBR_ELEMENT (child)) {
                                        /* If the processed HTML contained just
-                                        * the BR don't overwrite its class. */
-                                       if (!element_has_class (WEBKIT_DOM_ELEMENT (child), 
"-x-evo-first-br"))
-                                               element_add_class (
+                                        * the BR don't overwrite its id. */
+                                       if (!element_has_id (WEBKIT_DOM_ELEMENT (child), "-x-evo-first-br"))
+                                               webkit_dom_element_set_id (
                                                        WEBKIT_DOM_ELEMENT (child),
                                                        "-x-evo-last-br");
                                } else if (!view->priv->is_editting_message)
@@ -8025,12 +8025,10 @@ html_editor_convert_view_content (EHTMLEditorView *view,
                                document, WEBKIT_DOM_ELEMENT (child), NULL, NULL);
        }
 
-       paragraph = webkit_dom_document_query_selector (document, "br.-x-evo-last-br", NULL);
-       if (paragraph)
-               webkit_dom_element_remove_attribute (paragraph, "class");
-       paragraph = webkit_dom_document_query_selector (document, "br.-x-evo-first-br", NULL);
-       if (paragraph)
-               webkit_dom_element_remove_attribute (paragraph, "class");
+       if ((paragraph = webkit_dom_document_get_element_by_id (document, "-x-evo-last-br")))
+               webkit_dom_element_remove_attribute (paragraph, "id");
+       if ((paragraph = webkit_dom_document_get_element_by_id (document, "-x-evo-first-br")))
+               webkit_dom_element_remove_attribute (paragraph, "id");
 
        merge_siblings_if_necessary (document, NULL);
 
@@ -8319,27 +8317,11 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view,
                e_html_editor_view_quote_plain_text_element_after_wrapping (
                        document, WEBKIT_DOM_ELEMENT (current_block), citation_level);
 
-               /* If the pasted text begun or ended with a new line we have to
-                * quote these paragraphs as well */
-               br = webkit_dom_element_query_selector (
-                       WEBKIT_DOM_ELEMENT (last_paragraph), "br.-x-evo-last-br", NULL);
-               if (br) {
-                       WebKitDOMNode *parent;
-
-                       parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (br));
-                       quote_plain_text_recursive (document, parent, parent, citation_level);
+               if ((br = webkit_dom_document_get_element_by_id (document, "-x-evo-last-br")))
                        webkit_dom_element_remove_attribute (br, "class");
-               }
-
-               br = webkit_dom_document_query_selector (
-                       document, "* > br.-x-evo-first-br", NULL);
-               if (br) {
-                       WebKitDOMNode *parent;
 
-                       parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (br));
-                       quote_plain_text_recursive (document, parent, parent, citation_level);
+               if ((br = webkit_dom_document_get_element_by_id (document, "-x-evo-first-br")))
                        webkit_dom_element_remove_attribute (br, "class");
-               }
 
                e_html_editor_selection_restore (selection);
 
@@ -8372,7 +8354,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view,
        e_html_editor_selection_save (selection);
 
        element = webkit_dom_document_query_selector (
-               document, "* > br.-x-evo-first-br", NULL);
+               document, "* > br#-x-evo-first-br", NULL);
        if (element) {
                WebKitDOMNode *sibling;
                WebKitDOMNode *parent;
@@ -8388,7 +8370,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view,
        }
 
        element = webkit_dom_document_query_selector (
-               document, "* > br.-x-evo-last-br", NULL);
+               document, "* > br#-x-evo-last-br", NULL);
        if (element) {
                WebKitDOMNode *parent;
                WebKitDOMNode *child;


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