[evolution/wip/webkit2] EHTMLEditorTableDialog - Change how the table is inserted
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] EHTMLEditorTableDialog - Change how the table is inserted
- Date: Wed, 22 Apr 2015 13:09:58 +0000 (UTC)
commit 46a3c7bff8aee49aa8f97f32073edc79345702fb
Author: Tomas Popela <tpopela redhat com>
Date: Mon Mar 30 10:58:08 2015 +0200
EHTMLEditorTableDialog - Change how the table is inserted
Don't insert BR after the table, but insert the same block (but empty)
as current block. Also when we are inserting new table from empty block
replace it with newly created table (otherwise insert the table below
it).
.../e-html-editor-table-dialog-dom-functions.c | 55 +++++++++++--------
1 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/web-extensions/e-html-editor-table-dialog-dom-functions.c
b/web-extensions/e-html-editor-table-dialog-dom-functions.c
index a2b0bac..64ab7db 100644
--- a/web-extensions/e-html-editor-table-dialog-dom-functions.c
+++ b/web-extensions/e-html-editor-table-dialog-dom-functions.c
@@ -153,8 +153,11 @@ static void
create_table (WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension)
{
- WebKitDOMElement *table, *br, *caret, *parent, *element;
+ gboolean empty = FALSE;
+ gchar *text_content;
gint i;
+ WebKitDOMElement *table, *br, *caret, *element, *cell;
+ WebKitDOMNode *clone;
/* Default 3x3 table */
table = webkit_dom_document_create_element (document, "TABLE", NULL);
@@ -177,43 +180,49 @@ create_table (WebKitDOMDocument *document,
caret = webkit_dom_document_get_element_by_id (
document, "-x-evo-selection-end-marker");
- parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (caret));
- element = caret;
- while (!WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
- element = parent;
- parent = webkit_dom_node_get_parent_element (
- WEBKIT_DOM_NODE (parent));
- }
+ element = get_parent_block_element (WEBKIT_DOM_NODE (caret));
+ text_content = webkit_dom_node_get_text_content (WEBKIT_DOM_NODE (element));
+ empty = text_content && !*text_content;
+ g_free (text_content);
+ clone = webkit_dom_node_clone_node (WEBKIT_DOM_NODE (element), FALSE);
br = webkit_dom_document_create_element (document, "BR", NULL);
+ webkit_dom_node_append_child (clone, WEBKIT_DOM_NODE (br), NULL);
webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (parent),
- WEBKIT_DOM_NODE (br),
- webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
- NULL);
-
- /* Insert the table into body below the caret */
- webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (parent),
- WEBKIT_DOM_NODE (table),
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
+ clone,
webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
NULL);
/* Move caret to the first cell */
- element = webkit_dom_element_query_selector (table, "td", NULL);
+ cell = webkit_dom_element_query_selector (table, "td", NULL);
webkit_dom_node_append_child (
- WEBKIT_DOM_NODE (element),
- WEBKIT_DOM_NODE (caret),
- NULL);
+ WEBKIT_DOM_NODE (cell), WEBKIT_DOM_NODE (caret), NULL);
caret = webkit_dom_document_get_element_by_id (
document, "-x-evo-selection-start-marker");
webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (element),
+ WEBKIT_DOM_NODE (cell),
WEBKIT_DOM_NODE (caret),
- webkit_dom_node_get_last_child (WEBKIT_DOM_NODE (element)),
+ webkit_dom_node_get_last_child (WEBKIT_DOM_NODE (cell)),
NULL);
+ /* Insert the table into body unred the current block (if current block is not empty)
+ * otherwise replace the current block. */
+ if (empty) {
+ webkit_dom_node_replace_child (
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
+ WEBKIT_DOM_NODE (table),
+ WEBKIT_DOM_NODE (element),
+ NULL);
+ } else {
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
+ WEBKIT_DOM_NODE (table),
+ webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
+ NULL);
+ }
+
dom_selection_restore (document);
e_html_editor_web_extension_set_content_changed (extension);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]