[evolution/wip/webkit2] When pressing the Return key to end a list a new empty list is created
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] When pressing the Return key to end a list a new empty list is created
- Date: Fri, 1 Jul 2016 13:08:38 +0000 (UTC)
commit a9679f884a8d7032579bedcb06705e8695b579a4
Author: Tomas Popela <tpopela redhat com>
Date: Thu Jun 30 11:54:44 2016 +0200
When pressing the Return key to end a list a new empty list is created
Also fix the remove_node_if_empty function to correctly remove empty elements.
.../web-extension/e-editor-dom-functions.c | 2 +
web-extensions/e-dom-utils.c | 45 ++++++++++++++------
2 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index d51713b..e8afb22 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -9890,6 +9890,8 @@ e_editor_dom_return_pressed_in_empty_list_item (EEditorPage *editor_page)
list,
NULL);
+ remove_node_if_empty (list);
+
if (ev) {
e_editor_dom_selection_get_coordinates (editor_page,
&ev->after.start.x,
diff --git a/web-extensions/e-dom-utils.c b/web-extensions/e-dom-utils.c
index 5136f81..ef6248f 100644
--- a/web-extensions/e-dom-utils.c
+++ b/web-extensions/e-dom-utils.c
@@ -1591,23 +1591,41 @@ remove_node (WebKitDOMNode *node)
void
remove_node_if_empty (WebKitDOMNode *node)
{
+ WebKitDOMNode *child;
+
if (!WEBKIT_DOM_IS_NODE (node))
return;
- if (!webkit_dom_node_get_first_child (node)) {
- remove_node (node);
- } else {
- gchar *text_content;
+ if ((child = webkit_dom_node_get_first_child (node))) {
+ WebKitDOMNode *prev_sibling, *next_sibling;
+
+ prev_sibling = webkit_dom_node_get_previous_sibling (child);
+ next_sibling = webkit_dom_node_get_next_sibling (child);
+ /* Empty or BR as sibling, but no sibling after it. */
+ if (!webkit_dom_node_get_first_child (child) &&
+ !WEBKIT_DOM_IS_TEXT (child) &&
+ (!prev_sibling ||
+ (WEBKIT_DOM_IS_HTML_BR_ELEMENT (prev_sibling) &&
+ !webkit_dom_node_get_previous_sibling (prev_sibling))) &&
+ (!next_sibling ||
+ (WEBKIT_DOM_IS_HTML_BR_ELEMENT (next_sibling) &&
+ !webkit_dom_node_get_next_sibling (next_sibling)))) {
- text_content = webkit_dom_node_get_text_content (node);
- if (!text_content)
remove_node (node);
+ } else {
+ gchar *text_content;
- if (text_content && !*text_content)
- remove_node (node);
+ text_content = webkit_dom_node_get_text_content (node);
+ if (!text_content)
+ remove_node (node);
- g_free (text_content);
- }
+ if (text_content && !*text_content)
+ remove_node (node);
+
+ g_free (text_content);
+ }
+ } else
+ remove_node (node);
}
WebKitDOMNode *
@@ -1638,11 +1656,12 @@ split_list_into_two (WebKitDOMNode *item,
while (first_child && (sibling = webkit_dom_node_get_next_sibling (first_child)))
webkit_dom_node_insert_before (first_child, sibling, insert_before, NULL);
- while ((sibling = webkit_dom_node_get_next_sibling (tmp)))
+ while (tmp && (sibling = webkit_dom_node_get_next_sibling (tmp)))
webkit_dom_node_append_child (clone, sibling, NULL);
- webkit_dom_node_insert_before (
- clone, tmp, webkit_dom_node_get_first_child (clone), NULL);
+ if (tmp)
+ webkit_dom_node_insert_before (
+ clone, tmp, webkit_dom_node_get_first_child (clone), NULL);
prev_parent = parent;
tmp = webkit_dom_node_get_next_sibling (parent);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]