Blame SOURCES/evolution-3.28.5-composer-mangled-quotation.patch

956363
diff -up evolution-3.28.5/src/e-util/test-html-editor-units-bugs.c.composer-mangled-quotation evolution-3.28.5/src/e-util/test-html-editor-units-bugs.c
956363
--- evolution-3.28.5/src/e-util/test-html-editor-units-bugs.c.composer-mangled-quotation	2018-07-30 15:37:05.000000000 +0200
956363
+++ evolution-3.28.5/src/e-util/test-html-editor-units-bugs.c	2018-11-09 13:27:45.699170089 +0100
956363
@@ -1205,6 +1205,120 @@ test_bug_750636 (TestFixture *fixture)
956363
 		g_test_fail ();
956363
 }
956363
 
956363
+static void
956363
+test_issue_86 (TestFixture *fixture)
956363
+{
956363
+	const gchar *source_text =
956363
+		"normal text\n"
956363
+		"\n"
956363
+		"> level 1\n"
956363
+		"> level 1\n"
956363
+		"> > level 2\n"
956363
+		"> > level 2\n"
956363
+		"> >\n"
956363
+		"> > level 2\n"
956363
+		">\n"
956363
+		"> level 1\n"
956363
+		"> level 1\n"
956363
+		">\n"
956363
+		"> > > level 3\n"
956363
+		"> > > level 3\n"
956363
+		">\n"
956363
+		"> > level 2\n"
956363
+		"> > level 2\n"
956363
+		">\n"
956363
+		"> level 1\n"
956363
+		"\n"
956363
+		"back normal text\n";
956363
+	gchar *converted, *to_insert;
956363
+
956363
+	if (!test_utils_process_commands (fixture,
956363
+		"mode:html\n")) {
956363
+		g_test_fail ();
956363
+		return;
956363
+	}
956363
+
956363
+	converted = camel_text_to_html (source_text,
956363
+		CAMEL_MIME_FILTER_TOHTML_PRE |
956363
+		CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
956363
+		CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES |
956363
+		CAMEL_MIME_FILTER_TOHTML_QUOTE_CITATION,
956363
+		0xDDDDDD);
956363
+
956363
+	g_return_if_fail (converted != NULL);
956363
+
956363
+	to_insert = g_strconcat (converted,
956363
+		""
956363
+		"",
956363
+		NULL);
956363
+
956363
+	test_utils_insert_content (fixture, to_insert,
956363
+		E_CONTENT_EDITOR_INSERT_REPLACE_ALL | E_CONTENT_EDITOR_INSERT_TEXT_HTML);
956363
+
956363
+	if (!test_utils_run_simple_test (fixture,
956363
+		"",
956363
+		HTML_PREFIX "
On Today, User wrote:
"
956363
+		"
"
956363
+			"
normal text
"
956363
+			"

"
956363
+			"
"
956363
+				"
level 1
"
956363
+				"
level 1
"
956363
+				"
"
956363
+					"
level 2
"
956363
+					"
level 2
"
956363
+					"

"
956363
+					"
level 2
"
956363
+				""
956363
+				"

"
956363
+				"
level 1
"
956363
+				"
level 1
"
956363
+				"

"
956363
+				"
"
956363
+					"
"
956363
+						"
level 3
"
956363
+						"
level 3
"
956363
+					""
956363
+				""
956363
+				"

"
956363
+				"
"
956363
+					"
level 2
"
956363
+					"
level 2
"
956363
+				""
956363
+				"

"
956363
+				"
level 1
"
956363
+			""
956363
+			"

"
956363
+			"
back normal text
"
956363
+		"" HTML_SUFFIX,
956363
+		"On Today, User wrote:\n"
956363
+		"> normal text\n"
956363
+		"> \n"
956363
+		"> > level 1\n"
956363
+		"> > level 1\n"
956363
+		"> > > level 2\n"
956363
+		"> > > level 2\n"
956363
+		"> > > \n"
956363
+		"> > > level 2\n"
956363
+		"> > \n"
956363
+		"> > level 1\n"
956363
+		"> > level 1\n"
956363
+		"> > \n"
956363
+		"> > > > level 3\n"
956363
+		"> > > > level 3\n"
956363
+		"> > \n"
956363
+		"> > > level 2\n"
956363
+		"> > > level 2\n"
956363
+		"> > \n"
956363
+		"> > level 1\n"
956363
+		"> \n"
956363
+		"> back normal text"))
956363
+		g_test_fail ();
956363
+
956363
+	g_free (to_insert);
956363
+	g_free (converted);
956363
+}
956363
+
956363
 void
956363
 test_add_html_editor_bug_tests (void)
956363
 {
956363
@@ -1234,4 +1348,5 @@ test_add_html_editor_bug_tests (void)
956363
 	test_utils_add_test ("/bug/780088", test_bug_780088);
956363
 	test_utils_add_test ("/bug/788829", test_bug_788829);
956363
 	test_utils_add_test ("/bug/750636", test_bug_750636);
956363
+	test_utils_add_test ("/issue/86", test_issue_86);
956363
 }
956363
diff -up evolution-3.28.5/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c.composer-mangled-quotation evolution-3.28.5/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
956363
--- evolution-3.28.5/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c.composer-mangled-quotation	2018-07-30 15:37:05.000000000 +0200
956363
+++ evolution-3.28.5/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c	2018-11-09 13:29:06.551168971 +0100
956363
@@ -6230,7 +6230,6 @@ e_editor_dom_convert_content (EEditorPag
956363
 			WEBKIT_DOM_NODE (content_wrapper),
956363
 			WEBKIT_DOM_NODE (e_editor_dom_prepare_paragraph (editor_page, FALSE)),
956363
 			NULL);
956363
-
956363
 	if (!cite_body) {
956363
 		if (!empty) {
956363
 			WebKitDOMNode *child;
956363
@@ -8754,6 +8753,133 @@ adapt_to_editor_dom_changes (WebKitDOMDo
956363
 	g_clear_object (&collection);
956363
 }
956363
 
956363
+static void
956363
+traverse_nodes_to_split_pre (WebKitDOMDocument *document,
956363
+			     WebKitDOMNode *node,
956363
+			     WebKitDOMNode *new_parent, /* can be NULL, then prepend to out_new_nodes */
956363
+			     gboolean is_in_pre,
956363
+			     GSList **out_new_nodes) /* WebKitDOMNode * */
956363
+{
956363
+	if (is_in_pre && WEBKIT_DOM_IS_TEXT (node)) {
956363
+		gchar *text;
956363
+
956363
+		text = webkit_dom_text_get_whole_text (WEBKIT_DOM_TEXT (node));
956363
+		if (text) {
956363
+			WebKitDOMElement *pre;
956363
+			gint ii;
956363
+			gchar **strv;
956363
+
956363
+			strv = g_strsplit (text, "\n", -1);
956363
+
956363
+			for (ii = 0; strv && strv[ii]; ii++) {
956363
+				if (*(strv[ii])) {
956363
+					gint len = strlen (strv[ii]);
956363
+
956363
+					if (strv[ii][len - 1] == '\r') {
956363
+						strv[ii][len - 1] = '\0';
956363
+					}
956363
+				}
956363
+
956363
+				/* 
 is shown as a block, thus adding a new line at the end behaves like two 
-s */
956363
+				if (!*(strv[ii]) && !strv[ii + 1])
956363
+					break;
956363
+
956363
+				pre = webkit_dom_document_create_element (document, "pre", NULL);
956363
+
956363
+				if (*(strv[ii])) {
956363
+					webkit_dom_html_element_set_inner_text (WEBKIT_DOM_HTML_ELEMENT (pre), strv[ii], NULL);
956363
+				} else {
956363
+					WebKitDOMElement *br;
956363
+
956363
+					br = webkit_dom_document_create_element (document, "br", NULL);
956363
+					webkit_dom_node_append_child (WEBKIT_DOM_NODE (pre), WEBKIT_DOM_NODE (br), NULL);
956363
+				}
956363
+
956363
+				if (new_parent)
956363
+					webkit_dom_node_append_child (new_parent, WEBKIT_DOM_NODE (pre), NULL);
956363
+				else
956363
+					*out_new_nodes = g_slist_prepend (*out_new_nodes, pre);
956363
+			}
956363
+
956363
+			g_strfreev (strv);
956363
+		}
956363
+
956363
+		g_free (text);
956363
+	} else if (WEBKIT_DOM_IS_HTML_PRE_ELEMENT (node)) {
956363
+		is_in_pre = TRUE;
956363
+	} else {
956363
+		WebKitDOMNode *nd;
956363
+		GError *error = NULL;
956363
+
956363
+		nd = webkit_dom_node_clone_node_with_error (node, FALSE, &error);
956363
+		if (nd) {
956363
+			if (new_parent)
956363
+				webkit_dom_node_append_child (new_parent, nd, NULL);
956363
+			else
956363
+				*out_new_nodes = g_slist_prepend (*out_new_nodes, nd);
956363
+
956363
+			new_parent = nd;
956363
+		} else {
956363
+			g_warning ("%s: Failed to clone node %s: %s\n", G_STRFUNC, G_OBJECT_TYPE_NAME (node), error ? error->message : "Unknown error");
956363
+		}
956363
+	}
956363
+
956363
+	for (node = webkit_dom_node_get_first_child (node);
956363
+	     node;
956363
+	     node = webkit_dom_node_get_next_sibling (node)) {
956363
+		traverse_nodes_to_split_pre (document, node, new_parent, is_in_pre, out_new_nodes);
956363
+	}
956363
+}
956363
+
956363
+static void
956363
+maybe_split_pre_paragraphs (WebKitDOMDocument *document)
956363
+{
956363
+	WebKitDOMHTMLElement *body;
956363
+	WebKitDOMNodeList *list;
956363
+
956363
+	body = webkit_dom_document_get_body (document);
956363
+	if (!body)
956363
+		return;
956363
+
956363
+	list = webkit_dom_document_query_selector_all (document, "pre", NULL);
956363
+	if (webkit_dom_node_list_get_length (list)) {
956363
+		WebKitDOMNode *body_node, *node, *current;
956363
+		GSList *new_nodes = NULL, *to_remove = NULL, *link;
956363
+
956363
+		g_clear_object (&list);
956363
+
956363
+		body_node = WEBKIT_DOM_NODE (body);
956363
+		webkit_dom_node_normalize (body_node);
956363
+
956363
+		for (current = webkit_dom_node_get_first_child (body_node);
956363
+		     current;
956363
+		     current = webkit_dom_node_get_next_sibling (current)) {
956363
+			traverse_nodes_to_split_pre (document, current, NULL, FALSE, &new_nodes);
956363
+			to_remove = g_slist_prepend (to_remove, current);
956363
+		}
956363
+
956363
+		for (link = to_remove; link; link = g_slist_next (link)) {
956363
+			node = link->data;
956363
+
956363
+			webkit_dom_node_remove_child (body_node, node, NULL);
956363
+		}
956363
+
956363
+		/* They are in reverse order, thus reverse it */
956363
+		new_nodes = g_slist_reverse (new_nodes);
956363
+
956363
+		for (link = new_nodes; link; link = g_slist_next (link)) {
956363
+			node = link->data;
956363
+
956363
+			webkit_dom_node_append_child (body_node, node, NULL);
956363
+		}
956363
+
956363
+		g_slist_free (to_remove);
956363
+		g_slist_free (new_nodes);
956363
+	}
956363
+
956363
+	g_clear_object (&list);
956363
+}
956363
+
956363
 void
956363
 e_editor_dom_process_content_after_load (EEditorPage *editor_page)
956363
 {
956363
@@ -8803,60 +8929,8 @@ e_editor_dom_process_content_after_load
956363
 		}
956363
 
956363
 		goto out;
956363
-	} else {
956363
-		WebKitDOMNodeList *list;
956363
-		gulong ii;
956363
-
956363
-		list = webkit_dom_document_query_selector_all (document, "pre", NULL);
956363
-		for (ii = webkit_dom_node_list_get_length (list); ii--;) {
956363
-			WebKitDOMNode *node = webkit_dom_node_list_item (list, ii), *parent;
956363
-			WebKitDOMElement *element;
956363
-			gchar *inner_html;
956363
-
956363
-			element = WEBKIT_DOM_ELEMENT (node);
956363
-			parent = webkit_dom_node_get_parent_node (node);
956363
-			inner_html = webkit_dom_element_get_inner_html (element);
956363
-
956363
-			if (inner_html && *inner_html) {
956363
-				gchar **strv;
956363
-
956363
-				strv = g_strsplit (inner_html, "\n", -1);
956363
-				if (strv && strv[0] && strv[1]) {
956363
-					WebKitDOMElement *pre;
956363
-					gint jj;
956363
-
956363
-					for (jj = 0; strv[jj]; jj++) {
956363
-						pre = webkit_dom_document_create_element (document, "pre", NULL);
956363
-						if (*(strv[jj])) {
956363
-							gint len = strlen (strv[jj]);
956363
-
956363
-							if (strv[jj][len - 1] == '\r') {
956363
-								strv[jj][len - 1] = '\0';
956363
-							}
956363
-						}
956363
-
956363
-						if (*(strv[jj])) {
956363
-							webkit_dom_html_element_set_inner_html (WEBKIT_DOM_HTML_ELEMENT (pre), strv[jj], NULL);
956363
-						} else {
956363
-							WebKitDOMElement *br;
956363
-
956363
-							br = webkit_dom_document_create_element (document, "br", NULL);
956363
-							webkit_dom_node_append_child (WEBKIT_DOM_NODE (pre), WEBKIT_DOM_NODE (br), NULL);
956363
-						}
956363
-
956363
-						webkit_dom_node_insert_before (parent, WEBKIT_DOM_NODE (pre), node, NULL);
956363
-					}
956363
-
956363
-					remove_node (node);
956363
-				}
956363
-
956363
-				g_strfreev (strv);
956363
-			}
956363
-
956363
-			g_free (inner_html);
956363
-		}
956363
-
956363
-		g_clear_object (&list);
956363
+	} else if (!webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (body), "data-evo-draft")) {
956363
+		maybe_split_pre_paragraphs (document);
956363
 	}
956363
 
956363
 	adapt_to_editor_dom_changes (document);