[evolution] Pressing the Return key in the image wrapper will duplicate the image wrapper structure



commit 66a7f8bf37976eee7c4572b579e347b134a2e0e4
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Feb 26 10:23:09 2016 +0100

    Pressing the Return key in the image wrapper will duplicate the image wrapper structure
    
    To avoid that we need to do the things ourselves and avoid WebKit.

 e-util/e-html-editor-selection.c |    7 ---
 e-util/e-html-editor-utils.c     |    1 +
 e-util/e-html-editor-view.c      |   84 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 7 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index cd45dea..7294987 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -7587,13 +7587,6 @@ e_html_editor_selection_save (EHTMLEditorSelection *selection)
                        webkit_dom_node_get_first_child (container),
                        NULL);
                goto insert_end_marker;
-       } else if (element_has_class (WEBKIT_DOM_ELEMENT (container), "-x-evo-resizable-wrapper")) {
-               marker_node = webkit_dom_node_insert_before (
-                       parent_node,
-                       WEBKIT_DOM_NODE (start_marker),
-                       webkit_dom_node_get_next_sibling (container),
-                       NULL);
-               goto insert_end_marker;
        } else {
                /* Insert the selection marker on the right position in
                 * an empty paragraph in the quoted content */
diff --git a/e-util/e-html-editor-utils.c b/e-util/e-html-editor-utils.c
index 7a840d5..8cdd4ed 100644
--- a/e-util/e-html-editor-utils.c
+++ b/e-util/e-html-editor-utils.c
@@ -143,6 +143,7 @@ e_html_editor_get_parent_block_node_from_child (WebKitDOMNode *node)
            element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-quoted") ||
            element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-quote-character") ||
            element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-signature") ||
+           element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-resizable-wrapper") ||
            WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) ||
            element_has_tag (WEBKIT_DOM_ELEMENT (parent), "b") ||
            element_has_tag (WEBKIT_DOM_ELEMENT (parent), "i") ||
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index f99ea04..cfc5789 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -5472,6 +5472,87 @@ selection_is_in_empty_list_item (WebKitDOMNode *selection_start_marker)
 }
 
 static gboolean
+return_pressed_in_image_wrapper (EHTMLEditorView *view)
+{
+       EHTMLEditorSelection *selection;
+       EHTMLEditorViewHistoryEvent *ev = NULL;
+       WebKitDOMDocument *document;
+       WebKitDOMDocumentFragment *fragment;
+       WebKitDOMElement *selection_start_marker;
+       WebKitDOMNode *parent, *block, *clone;
+
+       selection = e_html_editor_view_get_selection (view);
+       if (!e_html_editor_selection_is_collapsed (selection))
+               return FALSE;
+
+       e_html_editor_selection_save (selection);
+
+       document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
+       selection_start_marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+
+       parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (selection_start_marker));
+       if (!element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-resizable-wrapper")) {
+               e_html_editor_selection_restore (selection);
+               return FALSE;
+       }
+
+       if (!view->priv->undo_redo_in_progress) {
+               ev = g_new0 (EHTMLEditorViewHistoryEvent, 1);
+               ev->type = HISTORY_INPUT;
+
+               e_html_editor_selection_get_selection_coordinates (
+                       selection,
+                       &ev->before.start.x,
+                       &ev->before.start.y,
+                       &ev->before.end.x,
+                       &ev->before.end.y);
+
+               fragment = webkit_dom_document_create_document_fragment (document);
+
+               g_object_set_data (
+                       G_OBJECT (fragment), "history-return-key", GINT_TO_POINTER (1));
+       }
+
+       block = e_html_editor_get_parent_block_node_from_child (
+               WEBKIT_DOM_NODE (selection_start_marker));
+
+       clone = webkit_dom_node_clone_node (block, FALSE);
+       webkit_dom_node_append_child (
+               clone, WEBKIT_DOM_NODE (webkit_dom_document_create_element (document, "br", NULL)), NULL);
+
+       webkit_dom_node_insert_before (
+               webkit_dom_node_get_parent_node (block),
+               clone,
+               block,
+               NULL);
+
+       if (ev) {
+               webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (fragment),
+                       webkit_dom_node_clone_node (clone, TRUE),
+                       NULL);
+
+               e_html_editor_selection_get_selection_coordinates (
+                       selection,
+                       &ev->after.start.x,
+                       &ev->after.start.y,
+                       &ev->after.end.x,
+                       &ev->after.end.y);
+
+               ev->data.fragment = fragment;
+
+               e_html_editor_view_insert_new_history_event (view, ev);
+       }
+
+       e_html_editor_view_set_changed (view, TRUE);
+
+       e_html_editor_selection_restore (selection);
+
+       return TRUE;
+}
+
+static gboolean
 return_pressed_in_empty_list_item (EHTMLEditorView *view)
 {
        EHTMLEditorSelection *selection;
@@ -5701,6 +5782,9 @@ key_press_event_process_return_key (EHTMLEditorView *view)
        if (return_pressed_in_empty_list_item (view))
                return TRUE;
 
+       if (return_pressed_in_image_wrapper (view))
+               return TRUE;
+
        return FALSE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]