[evolution] EHTMLEditorSelection - Trailing space is lost when wrapping content
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditorSelection - Trailing space is lost when wrapping content
- Date: Thu, 2 Apr 2015 12:18:00 +0000 (UTC)
commit 0c620c6ff8d451a352b7a7a6449e828006d4c0b7
Author: Tomas Popela <tpopela redhat com>
Date: Thu Apr 2 14:03:24 2015 +0200
EHTMLEditorSelection - Trailing space is lost when wrapping content
The thing is that the trailing space on the line is removed when wrapping,
but never returned back when editing the same block after.
e-util/e-html-editor-selection.c | 40 ++++++++++++++++++++++++++++++++++---
e-util/e-html-editor-view.c | 37 +++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 4 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 5a427ba..b0a044a 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -5724,6 +5724,23 @@ find_where_to_break_line (WebKitDOMNode *node,
return ret_val;
}
+static void
+mark_and_remove_leading_space (WebKitDOMDocument *document,
+ WebKitDOMNode *node)
+{
+ WebKitDOMElement *element;
+
+ element = webkit_dom_document_create_element (document, "SPAN", NULL);
+ webkit_dom_element_set_attribute (element, "data-hidden-space", "", NULL);
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (node),
+ WEBKIT_DOM_NODE (element),
+ node,
+ NULL);
+ webkit_dom_character_data_replace_data (
+ WEBKIT_DOM_CHARACTER_DATA (node), 0, 1, "", NULL);
+}
+
static WebKitDOMElement *
wrap_lines (EHTMLEditorSelection *selection,
WebKitDOMNode *paragraph,
@@ -5843,6 +5860,23 @@ wrap_lines (EHTMLEditorSelection *selection,
start_node = node;
}
+ if (start_node && WEBKIT_DOM_IS_ELEMENT (start_node)) {
+ WebKitDOMNodeList *list;
+
+ list = webkit_dom_element_query_selector_all (
+ WEBKIT_DOM_ELEMENT (start_node), "span[data-hidden-space]", NULL);
+ len = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < len; ii++) {
+ WebKitDOMNode *hidden_space_node;
+
+ hidden_space_node = webkit_dom_node_list_item (list, ii);
+ webkit_dom_html_element_set_outer_text (
+ WEBKIT_DOM_HTML_ELEMENT (hidden_space_node), " ", NULL);
+ g_object_unref (hidden_space_node);
+ }
+ g_object_unref (list);
+ }
+
len = 0;
while (node) {
gint offset = 0;
@@ -6019,8 +6053,7 @@ wrap_lines (EHTMLEditorSelection *selection,
nd_content = webkit_dom_node_get_text_content (nd);
if (nd_content && *nd_content) {
if (g_str_has_prefix (nd_content, " "))
- webkit_dom_character_data_replace_data (
- WEBKIT_DOM_CHARACTER_DATA (nd), 0, 1, "",
NULL);
+ mark_and_remove_leading_space (document, nd);
g_free (nd_content);
nd_content = webkit_dom_node_get_text_content (nd);
if (g_strcmp0 (nd_content, UNICODE_NBSP) == 0)
@@ -6052,8 +6085,7 @@ wrap_lines (EHTMLEditorSelection *selection,
nd_content = webkit_dom_node_get_text_content (nd);
if (nd_content && *nd_content) {
if (g_str_has_prefix (nd_content, " "))
- webkit_dom_character_data_replace_data (
- WEBKIT_DOM_CHARACTER_DATA (nd), 0, 1, "",
NULL);
+ mark_and_remove_leading_space (document, nd);
g_free (nd_content);
nd_content = webkit_dom_node_get_text_content (nd);
if (g_strcmp0 (nd_content, UNICODE_NBSP) == 0)
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 30355ee..7b7c5c9 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -8759,10 +8759,12 @@ process_content_for_plain_text (EHTMLEditorView *view)
static gchar *
process_content_for_html (EHTMLEditorView *view)
{
+ gint ii, length;
gchar *html_content;
WebKitDOMDocument *document;
WebKitDOMElement *marker;
WebKitDOMNode *node, *document_clone;
+ WebKitDOMNodeList *list;
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
document_clone = webkit_dom_node_clone_node (
@@ -8791,6 +8793,18 @@ process_content_for_html (EHTMLEditorView *view)
if (marker)
remove_node (WEBKIT_DOM_NODE (marker));
+ list = webkit_dom_element_query_selector_all (
+ WEBKIT_DOM_ELEMENT (node), "span[data-hidden-space]", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *hidden_space_node;
+
+ hidden_space_node = webkit_dom_node_list_item (list, ii);
+ remove_node (hidden_space_node);
+ g_object_unref (hidden_space_node);
+ }
+ g_object_unref (list);
+
process_elements (view, node, TRUE, FALSE, FALSE, NULL);
html_content = webkit_dom_html_element_get_outer_html (
@@ -9190,6 +9204,28 @@ toggle_tables (EHTMLEditorView *view)
g_object_unref (list);
}
+static void
+replace_hidden_spaces (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, "span[data-hidden-space]", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *hidden_space_node;
+
+ hidden_space_node = webkit_dom_node_list_item (list, ii);
+ webkit_dom_html_element_set_outer_text (
+ WEBKIT_DOM_HTML_ELEMENT (hidden_space_node), " ", NULL);
+ g_object_unref (hidden_space_node);
+ }
+ g_object_unref (list);
+}
+
/**
* e_html_editor_view_set_html_mode:
* @view: an #EHTMLEditorView
@@ -9266,6 +9302,7 @@ e_html_editor_view_set_html_mode (EHTMLEditorView *view,
toggle_smileys (view);
toggle_tables (view);
remove_wrapping_from_view (view);
+ replace_hidden_spaces (view);
} else {
gchar *plain;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]