[evolution/wip/webkit2] EHTMLEditorSelection - Trailing and leading spaces could be lost
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] EHTMLEditorSelection - Trailing and leading spaces could be lost
- Date: Wed, 2 Mar 2016 13:23:02 +0000 (UTC)
commit 331629003ffad584b851bf0ae35b7e936755a433
Author: Tomas Popela <tpopela redhat com>
Date: Wed Mar 2 14:21:06 2016 +0100
EHTMLEditorSelection - Trailing and leading spaces could be lost
.../e-html-editor-selection-dom-functions.c | 96 ++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/web-extensions/composer/e-html-editor-selection-dom-functions.c
b/web-extensions/composer/e-html-editor-selection-dom-functions.c
index 3f1c061..70ad1a3 100644
--- a/web-extensions/composer/e-html-editor-selection-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-selection-dom-functions.c
@@ -4904,6 +4904,83 @@ dom_selection_get_block_format (WebKitDOMDocument *document,
return result;
}
+static void
+change_leading_space_to_nbsp (WebKitDOMNode *block)
+{
+ WebKitDOMNode *child;
+
+ if (!WEBKIT_DOM_IS_HTML_PRE_ELEMENT (block))
+ return;
+
+ if ((child = webkit_dom_node_get_first_child (block)) &&
+ WEBKIT_DOM_IS_CHARACTER_DATA (child)) {
+ gchar *data;
+
+ data = webkit_dom_character_data_substring_data (
+ WEBKIT_DOM_CHARACTER_DATA (child), 0, 1, NULL);
+
+ if (data && *data == ' ')
+ webkit_dom_character_data_replace_data (
+ WEBKIT_DOM_CHARACTER_DATA (child), 0, 1, UNICODE_NBSP, NULL);
+ g_free (data);
+ }
+}
+
+static void
+change_trailing_space_in_block_to_nbsp (WebKitDOMNode *block)
+{
+ WebKitDOMNode *child;
+
+ if ((child = webkit_dom_node_get_last_child (block)) &&
+ WEBKIT_DOM_IS_CHARACTER_DATA (child)) {
+ gchar *tmp;
+ gulong length;
+
+ length = webkit_dom_character_data_get_length (
+ WEBKIT_DOM_CHARACTER_DATA (child));
+
+ tmp = webkit_dom_character_data_substring_data (
+ WEBKIT_DOM_CHARACTER_DATA (child), length - 1, 1, NULL);
+ if (tmp && *tmp == ' ') {
+ webkit_dom_character_data_replace_data (
+ WEBKIT_DOM_CHARACTER_DATA (child),
+ length - 1,
+ 1,
+ UNICODE_NBSP,
+ NULL);
+ }
+ g_free (tmp);
+ }
+}
+
+static void
+change_space_before_selection_to_nbsp (WebKitDOMNode *node)
+{
+ WebKitDOMNode *prev_sibling;
+
+ if ((prev_sibling = webkit_dom_node_get_previous_sibling (node))) {
+ if (WEBKIT_DOM_IS_CHARACTER_DATA (prev_sibling)) {
+ gchar *tmp;
+ gulong length;
+
+ length = webkit_dom_character_data_get_length (
+ WEBKIT_DOM_CHARACTER_DATA (prev_sibling));
+
+ tmp = webkit_dom_character_data_substring_data (
+ WEBKIT_DOM_CHARACTER_DATA (prev_sibling), length - 1, 1, NULL);
+ if (tmp && *tmp == ' ') {
+ webkit_dom_character_data_replace_data (
+ WEBKIT_DOM_CHARACTER_DATA (prev_sibling),
+ length - 1,
+ 1,
+ UNICODE_NBSP,
+ NULL);
+ }
+ g_free (tmp);
+ }
+ }
+}
+
static gboolean
process_block_to_block (WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension,
@@ -4986,6 +5063,9 @@ process_block_to_block (WebKitDOMDocument *document,
empty = !*content || (g_strcmp0 (content, UNICODE_ZERO_WIDTH_SPACE) == 0);
g_free (content);
+ change_leading_space_to_nbsp (block);
+ change_trailing_space_in_block_to_nbsp (block);
+
while ((child = webkit_dom_node_get_first_child (block))) {
if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (child))
empty = FALSE;
@@ -5216,6 +5296,9 @@ format_change_block_to_list (WebKitDOMDocument *document,
empty = !*content || (g_strcmp0 (content, UNICODE_ZERO_WIDTH_SPACE) == 0);
g_free (content);
+ change_leading_space_to_nbsp (block);
+ change_trailing_space_in_block_to_nbsp (block);
+
while ((child = webkit_dom_node_get_first_child (block))) {
if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (child))
empty = FALSE;
@@ -5732,6 +5815,19 @@ dom_selection_set_block_format (WebKitDOMDocument *document,
g_object_unref (range);
+ if (current_format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PRE) {
+ WebKitDOMElement *selection_marker;
+
+ selection_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ if (selection_marker)
+ change_space_before_selection_to_nbsp (WEBKIT_DOM_NODE (selection_marker));
+ selection_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
+ if (selection_marker)
+ change_space_before_selection_to_nbsp (WEBKIT_DOM_NODE (selection_marker));
+ }
+
if (from_list && to_list)
format_change_list_to_list (document, extension, format, html_mode);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]