[evolution/gnome-3-20] EHTMLEditorView - Indented elements should be preserved when switching between composer modes
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-20] EHTMLEditorView - Indented elements should be preserved when switching between composer modes
- Date: Tue, 28 Jun 2016 14:38:53 +0000 (UTC)
commit 694190358ace93b033920e9bb768b02379c8324b
Author: Tomas Popela <tpopela redhat com>
Date: Tue Jun 28 11:29:53 2016 +0200
EHTMLEditorView - Indented elements should be preserved when switching between composer modes
e-util/e-html-editor-selection.c | 15 +++++++++++++--
e-util/e-html-editor-utils.c | 19 +++++++++++++++++++
e-util/e-html-editor-utils.h | 4 ++++
e-util/e-html-editor-view.c | 35 +++++++++++++++++++++++++++++------
4 files changed, 65 insertions(+), 8 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 3b8058a..6b0802f 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -7100,12 +7100,23 @@ e_html_editor_selection_set_indented_style (EHTMLEditorSelection *selection,
webkit_dom_element_set_class_name (element, "-x-evo-indented");
- if (is_in_html_mode (selection) || word_wrap_length == 0)
+ if (is_in_html_mode (selection) || word_wrap_length == 0) {
+ gchar *plain_text_style;
+
style = g_strdup_printf ("margin-left: %dch;", SPACES_PER_INDENTATION);
- else
+
+ plain_text_style = g_strdup_printf (
+ "margin-left: %dch; word-wrap: normal; width: %dch;",
+ SPACES_PER_INDENTATION, word_wrap_length);
+
+ webkit_dom_element_set_attribute (
+ element, "data-plain-text-style", plain_text_style, NULL);
+ g_free (plain_text_style);
+ } else {
style = g_strdup_printf (
"margin-left: %dch; word-wrap: normal; width: %dch;",
SPACES_PER_INDENTATION, word_wrap_length);
+ }
webkit_dom_element_set_attribute (element, "style", style, NULL);
g_free (style);
diff --git a/e-util/e-html-editor-utils.c b/e-util/e-html-editor-utils.c
index ce8cb26..4917f7b 100644
--- a/e-util/e-html-editor-utils.c
+++ b/e-util/e-html-editor-utils.c
@@ -630,3 +630,22 @@ dom_element_rename_attribute (WebKitDOMElement *element,
webkit_dom_element_remove_attribute (element, from);
g_free (value);
}
+
+void
+dom_element_swap_attributes (WebKitDOMElement *element,
+ const gchar *from,
+ const gchar *to)
+{
+ gchar *value_from, *value_to;
+
+ if (!webkit_dom_element_has_attribute (element, from) ||
+ !webkit_dom_element_has_attribute (element, to))
+ return;
+
+ value_from = webkit_dom_element_get_attribute (element, from);
+ value_to = webkit_dom_element_get_attribute (element, to);
+ webkit_dom_element_set_attribute (element, to, (value_from && *value_from) ? value_from : "", NULL);
+ webkit_dom_element_set_attribute (element, from, (value_to && *value_to) ? value_to : "", NULL);
+ g_free (value_from);
+ g_free (value_to);
+}
diff --git a/e-util/e-html-editor-utils.h b/e-util/e-html-editor-utils.h
index 8611131..64da046 100644
--- a/e-util/e-html-editor-utils.h
+++ b/e-util/e-html-editor-utils.h
@@ -106,6 +106,10 @@ WebKitDOMElement *
void dom_element_rename_attribute (WebKitDOMElement *element,
const gchar *from,
const gchar *to);
+
+void dom_element_swap_attributes (WebKitDOMElement *element,
+ const gchar *from,
+ const gchar *to);
G_END_DECLS
#endif /* E_HTML_EDITOR_UTILS_H */
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 858bec4..d360fa7 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -7282,12 +7282,8 @@ create_and_append_new_block (EHTMLEditorSelection *selection,
{
WebKitDOMElement *block;
- if (WEBKIT_DOM_IS_HTML_DIV_ELEMENT (block_template))
- block = e_html_editor_selection_get_paragraph_element (
- selection, document, -1, 0);
- else
- block = WEBKIT_DOM_ELEMENT (webkit_dom_node_clone_node (
- WEBKIT_DOM_NODE (block_template), FALSE));
+ block = WEBKIT_DOM_ELEMENT (webkit_dom_node_clone_node (
+ WEBKIT_DOM_NODE (block_template), FALSE));
webkit_dom_html_element_set_inner_html (
WEBKIT_DOM_HTML_ELEMENT (block),
@@ -9534,6 +9530,7 @@ remove_evolution_attributes (WebKitDOMElement *element)
webkit_dom_element_remove_attribute (element, "data-new-message");
webkit_dom_element_remove_attribute (element, "data-user-wrapped");
webkit_dom_element_remove_attribute (element, "data-evo-plain-text");
+ webkit_dom_element_remove_attribute (element, "data-plain-text-style");
webkit_dom_element_remove_attribute (element, "data-style");
webkit_dom_element_remove_attribute (element, "spellcheck");
}
@@ -9883,6 +9880,7 @@ process_elements (EHTMLEditorView *view,
if (!to_plain_text && !changing_mode) {
process_blockquote (WEBKIT_DOM_ELEMENT (child), FALSE);
element_remove_class (WEBKIT_DOM_ELEMENT (child), "-x-evo-indented");
+ remove_evolution_attributes (WEBKIT_DOM_ELEMENT (child));
} else
process_blockquote (WEBKIT_DOM_ELEMENT (child), TRUE);
@@ -11159,6 +11157,29 @@ e_html_editor_view_clear_history (EHTMLEditorView *view)
}
static void
+toggle_indented_elements (EHTMLEditorView *view)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMNodeList *list;
+ gint ii, length;
+
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
+ list = webkit_dom_document_query_selector_all (document, ".-x-evo-indented", NULL);
+ length = webkit_dom_node_list_get_length (list);
+
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+
+ if (view->priv->html_mode)
+ dom_element_swap_attributes (WEBKIT_DOM_ELEMENT (node), "style",
"data-plain-text-style");
+ else
+ dom_element_swap_attributes (WEBKIT_DOM_ELEMENT (node), "data-plain-text-style",
"style");
+ g_object_unref (node);
+ }
+ g_object_unref (list);
+}
+
+static void
toggle_tables (EHTMLEditorView *view)
{
WebKitDOMDocument *document;
@@ -11311,6 +11332,7 @@ e_html_editor_view_set_html_mode (EHTMLEditorView *view,
toggle_paragraphs_style (view);
toggle_smileys (view);
toggle_tables (view);
+ toggle_indented_elements (view);
toggle_unordered_lists (view);
remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (body));
@@ -11329,6 +11351,7 @@ e_html_editor_view_set_html_mode (EHTMLEditorView *view,
toggle_paragraphs_style (view);
toggle_smileys (view);
toggle_tables (view);
+ toggle_indented_elements (view);
toggle_unordered_lists (view);
remove_images (view);
body = webkit_dom_document_get_body (document);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]