[evolution/wip/webkit2] EHTMLEditorSelection - Blocks are wrongly wrapped around selection markers
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] EHTMLEditorSelection - Blocks are wrongly wrapped around selection markers
- Date: Tue, 1 Mar 2016 14:49:41 +0000 (UTC)
commit 660cc84c548ff0bbb1cab093e5d190c7ccaade05
Author: Tomas Popela <tpopela redhat com>
Date: Tue Mar 1 15:42:21 2016 +0100
EHTMLEditorSelection - Blocks are wrongly wrapped around selection markers
.../e-html-editor-selection-dom-functions.c | 88 +++++++++++++++----
1 files changed, 69 insertions(+), 19 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 f645f3e..fea1d67 100644
--- a/web-extensions/composer/e-html-editor-selection-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-selection-dom-functions.c
@@ -2166,6 +2166,7 @@ wrap_lines (WebKitDOMDocument *document,
gulong length_left;
gchar *text_content;
gboolean compensated = FALSE;
+ gboolean check_next_node = FALSE;
has_selection = !dom_selection_is_collapsed (document);
@@ -2231,10 +2232,12 @@ wrap_lines (WebKitDOMDocument *document,
WebKitDOMNode *nd = WEBKIT_DOM_NODE (selection_end_marker);
while (nd) {
+ WebKitDOMNode *parent_node;
WebKitDOMNode *next_nd = webkit_dom_node_get_next_sibling (nd);
- if (!next_nd && !webkit_dom_node_is_same_node
(webkit_dom_node_get_parent_node (nd), block_clone))
- next_nd = webkit_dom_node_get_next_sibling
(webkit_dom_node_get_parent_node (nd));
+ parent_node = webkit_dom_node_get_parent_node (nd);
+ if (!next_nd && parent_node && !webkit_dom_node_is_same_node (parent_node,
block_clone))
+ next_nd = webkit_dom_node_get_next_sibling (parent_node);
if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (nd)) {
if (remove_all_br)
@@ -2387,10 +2390,19 @@ wrap_lines (WebKitDOMDocument *document,
g_free (text_content);
} else {
if (dom_is_selection_position_node (node)) {
+ if (line_length == 0) {
+ WebKitDOMNode *tmp_node;
+
+ tmp_node = webkit_dom_node_get_previous_sibling (node);
+ /* Only check if there is some node before the selection marker. */
+ if (tmp_node && !dom_is_selection_position_node (tmp_node))
+ check_next_node = TRUE;
+ }
node = webkit_dom_node_get_next_sibling (node);
continue;
}
+ check_next_node = FALSE;
/* If element is ANCHOR we wrap it separately */
if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (node)) {
glong anchor_length;
@@ -2482,14 +2494,25 @@ wrap_lines (WebKitDOMDocument *document,
WEBKIT_DOM_CHARACTER_DATA (node));
if ((length_left + line_length) <= length_to_wrap) {
+ if (check_next_node)
+ goto check_node;
line_length += length_left;
+ if (line_length == length_to_wrap)
+ line_length = 0;
goto next_node;
}
/* wrap until we have something */
while (node && (length_left + line_length) > length_to_wrap) {
+ gboolean insert_and_continue;
gint max_length;
+ check_node:
+ insert_and_continue = FALSE;
+
+ if (!WEBKIT_DOM_IS_CHARACTER_DATA (node))
+ goto next_node;
+
element = webkit_dom_document_create_element (document, "BR", NULL);
element_add_class (element, "-x-evo-wrap-br");
@@ -2497,6 +2520,11 @@ wrap_lines (WebKitDOMDocument *document,
if (max_length < 0)
max_length = length_to_wrap;
else if (max_length == 0) {
+ if (check_next_node) {
+ insert_and_continue = TRUE;
+ goto check;
+ }
+
/* Break before the current node and continue. */
webkit_dom_node_insert_before (
webkit_dom_node_get_parent_node (node),
@@ -2523,9 +2551,11 @@ wrap_lines (WebKitDOMDocument *document,
* split after the last character that will fit on the
* previous line. To avoid that we need to put the
* concatenated word on the next line. */
- if (offset == -1) {
+ if (offset == -1 || check_next_node) {
WebKitDOMNode *prev_sibling;
+ check:
+ check_next_node = FALSE;
prev_sibling = webkit_dom_node_get_previous_sibling (node);
if (prev_sibling && dom_is_selection_position_node (prev_sibling)) {
prev_sibling = webkit_dom_node_get_previous_sibling
(prev_sibling);
@@ -2588,7 +2618,20 @@ wrap_lines (WebKitDOMDocument *document,
}
}
}
- offset = max_length;
+ if (insert_and_continue) {
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (node),
+ WEBKIT_DOM_NODE (element),
+ node,
+ NULL);
+
+ offset = 0;
+ line_length = 0;
+ insert_and_continue = FALSE;
+ continue;
+ }
+
+ offset = offset != -1 ? offset : max_length;
}
}
@@ -2603,28 +2646,28 @@ wrap_lines (WebKitDOMDocument *document,
if (nd) {
gchar *nd_content;
+
nd_content = webkit_dom_node_get_text_content (nd);
if (nd_content && *nd_content) {
if (*nd_content == ' ')
mark_and_remove_leading_space (document, nd);
g_free (nd_content);
- nd_content = webkit_dom_node_get_text_content (nd);
- if (!*nd_content)
- remove_node (nd);
- g_free (nd_content);
}
- if (nd) {
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (node),
- WEBKIT_DOM_NODE (element),
- nd,
- NULL);
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (node),
+ WEBKIT_DOM_NODE (element),
+ nd,
+ NULL);
- node = webkit_dom_node_get_next_sibling (
- WEBKIT_DOM_NODE (element));
- offset = 0;
- }
+ offset = 0;
+
+ nd_content = webkit_dom_node_get_text_content (nd);
+ if (!*nd_content)
+ remove_node (nd);
+ g_free (nd_content);
+ node = webkit_dom_node_get_next_sibling (
+ WEBKIT_DOM_NODE (element));
} else {
webkit_dom_node_append_child (
webkit_dom_node_get_parent_node (node),
@@ -2638,7 +2681,7 @@ wrap_lines (WebKitDOMDocument *document,
node,
NULL);
}
- if (node)
+ if (node && WEBKIT_DOM_IS_CHARACTER_DATA (node))
length_left = webkit_dom_character_data_get_length (
WEBKIT_DOM_CHARACTER_DATA (node));
@@ -2715,6 +2758,13 @@ wrap_lines (WebKitDOMDocument *document,
return NULL;
} else {
+ WebKitDOMNode *last_child;
+
+ last_child = webkit_dom_node_get_last_child (block_clone);
+ if (last_child && WEBKIT_DOM_IS_HTML_BR_ELEMENT (last_child) &&
+ element_has_class (WEBKIT_DOM_ELEMENT (last_child), "-x-evo-wrap-br"))
+ remove_node (last_child);
+
webkit_dom_node_normalize (block_clone);
node = webkit_dom_node_get_parent_node (block);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]