[evolution] EHTMLEditorView - Signature in a message can lost its line breaks after sending it
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditorView - Signature in a message can lost its line breaks after sending it
- Date: Fri, 11 Mar 2016 11:50:23 +0000 (UTC)
commit e5d99f5e3706158efb6dabdb3f70c970206d909a
Author: Tomas Popela <tpopela redhat com>
Date: Fri Mar 11 12:39:27 2016 +0100
EHTMLEditorView - Signature in a message can lost its line breaks after sending it
Fix various problems with line breaks in signatures:
* Correctly process the signature when generating the plain text version of the
composer's content.
* Always convert the signature if composer is in the HTML mode.
* Remove a line break on the end of the signature (from PRE element) as it is
not being displayed by WebKit, but it is shown in the final output.
* Also remove the already unneeded code that was fixing the signature when the
return key was pressed in it.
e-util/e-html-editor-view.c | 102 ++++++++++++++++++++-----------------------
1 files changed, 48 insertions(+), 54 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index f9ab4c9..dce3f15 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -9918,6 +9918,7 @@ process_elements (EHTMLEditorView *view,
first_child = webkit_dom_node_get_first_child (child);
+ skip_node = TRUE;
/* Don't generate any text if the signature is set to None. */
if (!changing_mode) {
gchar *id;
@@ -9927,7 +9928,6 @@ process_elements (EHTMLEditorView *view,
g_free (id);
remove_node (child);
- skip_node = TRUE;
goto next;
}
g_free (id);
@@ -9940,63 +9940,57 @@ process_elements (EHTMLEditorView *view,
WEBKIT_DOM_ELEMENT (first_child));
remove_evolution_attributes (
WEBKIT_DOM_ELEMENT (first_child));
- }
- if (to_plain_text && !changing_mode) {
- WebKitDOMDocument *document;
- WebKitDOMNodeList *list_pre;
- gint jj, pre_count;
+ if (!changing_mode)
+ skip_node = FALSE;
+ } else if (changing_mode) {
+ content = webkit_dom_html_element_get_outer_html (
+ WEBKIT_DOM_HTML_ELEMENT (child));
+ g_string_append (buffer, content);
+ g_free (content);
+ } else {
g_string_append (buffer, "\n");
- /* If the user edited the signature or added more
- * content after it, WebKit just duplicated the DOM
- * structure and left us with multiple PRE elements
- * that don't have the BR elements on their ends.
- * The content is rendered fine (every pre has its
- * own line), but when we below try to get a plain text
- * version of the signature we will get the text from
- * these PRE elements on one line. As a solution we need
- * to insert the BR elements on the end of each PRE
- * element (if not presented) to get the correct text
- * from signature. */
- document = webkit_dom_node_get_owner_document (child);
- list_pre = webkit_dom_element_query_selector_all (
- WEBKIT_DOM_ELEMENT (first_child), "pre", NULL);
- pre_count = webkit_dom_node_list_get_length (list_pre);
- for (jj = 0; jj < pre_count; jj++) {
- WebKitDOMNode *last_pre_child, *pre_node;
-
- pre_node = webkit_dom_node_list_item (list_pre, jj);
- last_pre_child = webkit_dom_node_get_last_child (pre_node);
-
- if (last_pre_child && !WEBKIT_DOM_IS_HTMLBR_ELEMENT (last_pre_child))
{
- WebKitDOMElement *br;
-
- br = webkit_dom_document_create_element (document, "br",
NULL);
- webkit_dom_node_append_child (
- pre_node, WEBKIT_DOM_NODE (br), NULL);
+ if (view->priv->html_mode) {
+ convert_element_from_html_to_plain_text (
+ view, WEBKIT_DOM_ELEMENT (first_child), NULL, NULL);
+ } else {
+ WebKitDOMNode *signature_node;
+
+ signature_node = webkit_dom_node_get_last_child (first_child);
+ if (WEBKIT_DOM_IS_HTML_PRE_ELEMENT (signature_node)) {
+ WebKitDOMNode *last_child;
+
+ /* Remove a line break on the end of the last
+ * PRE element. It is not showed by the WebKit,
+ * but it is still there are will be added to
+ * the output. */
+ last_child = webkit_dom_node_get_last_child (signature_node);
+ if (WEBKIT_DOM_IS_CHARACTER_DATA (last_child)) {
+ WebKitDOMCharacterData *data;
+ glong length;
+
+ data = WEBKIT_DOM_CHARACTER_DATA (last_child);
+ length = webkit_dom_character_data_get_length (data);
+ if (length > 0) {
+ gchar *last_char;
+
+ last_char =
webkit_dom_character_data_substring_data (
+ data, length - 1, 1, NULL);
+
+ if (last_char && *last_char == '\n')
+ webkit_dom_character_data_delete_data
(
+ data, length -1, 1, NULL);
+
+ g_free (last_char);
+ }
+ }
}
- g_object_unref (pre_node);
}
- g_object_unref (list_pre);
-
- convert_element_from_html_to_plain_text (
- view, WEBKIT_DOM_ELEMENT (first_child), NULL, NULL);
- content = webkit_dom_html_element_get_inner_text (
- WEBKIT_DOM_HTML_ELEMENT (first_child));
- g_string_append (buffer, content);
- g_free (content);
+ skip_node = FALSE;
skip_nl = TRUE;
}
- if (to_plain_text && changing_mode) {
- content = webkit_dom_html_element_get_outer_html (
- WEBKIT_DOM_HTML_ELEMENT (child));
- g_string_append (buffer, content);
- g_free (content);
- }
- skip_node = TRUE;
- if (!to_plain_text && !changing_mode)
- skip_node = FALSE;
+
goto next;
}
@@ -10035,15 +10029,15 @@ process_elements (EHTMLEditorView *view,
/* Leave PRE elements untouched */
if (WEBKIT_DOM_IS_HTML_PRE_ELEMENT (child)) {
- if (changing_mode && to_plain_text) {
+ if (!to_plain_text) {
+ remove_evolution_attributes (WEBKIT_DOM_ELEMENT (child));
+ } else if (changing_mode) {
content = webkit_dom_html_element_get_outer_html (
WEBKIT_DOM_HTML_ELEMENT (child));
g_string_append (buffer, content);
g_free (content);
skip_node = TRUE;
}
- if (!to_plain_text)
- remove_evolution_attributes (WEBKIT_DOM_ELEMENT (child));
}
if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (child)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]