[evolution/wip/webkit2] Introduce a new test for pressing a Return key after the HR element
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] Introduce a new test for pressing a Return key after the HR element
- Date: Thu, 21 Jul 2016 12:03:53 +0000 (UTC)
commit e795f6cc1ee5a088e5b1e8ab1fd96b36465f04a9
Author: Tomas Popela <tpopela redhat com>
Date: Thu Jul 21 14:00:10 2016 +0200
Introduce a new test for pressing a Return key after the HR element
And fix the code to do it correctly - previously no block was inserted after the
HR element thus the user could write straight into the BODY element (but this is
harmless as there is a code that wraps the text into the block). Also fix the
undo and redo for this action.
e-util/test-html-editor-units.c | 16 +++
.../web-extension/e-editor-dom-functions.c | 114 ++++++++++++++++++++
.../web-extension/e-editor-undo-redo-manager.c | 45 ++++++++-
3 files changed, 173 insertions(+), 2 deletions(-)
---
diff --git a/e-util/test-html-editor-units.c b/e-util/test-html-editor-units.c
index 8df592d..2649614 100644
--- a/e-util/test-html-editor-units.c
+++ b/e-util/test-html-editor-units.c
@@ -638,6 +638,21 @@ test_h_rule_insert (TestFixture *fixture)
g_test_fail ();
}
+static void
+test_h_rule_insert_text_after (TestFixture *fixture)
+{
+ if (!test_utils_run_simple_test (fixture,
+ "mode:html\n"
+ "type:above\n"
+ "action:insert-rule\n"
+ "seq:tttttn\n" /* Move to the Close button and press it */
+ "seq:den\n"
+ "type:below\n",
+ HTML_PREFIX "<p>above</p><hr align=\"left\" size=\"2\" noshade=\"\"><p>below</p>" HTML_SUFFIX,
+ "above\nbelow"))
+ g_test_fail ();
+}
+
gint
main (gint argc,
gchar *argv[])
@@ -722,6 +737,7 @@ main (gint argc,
add_test ("/insert/link/typed/change-description", test_insert_link_typed_change_description);
add_test ("/insert/link/typed/remove", test_insert_link_typed_remove);
add_test ("/h-rule/insert", test_h_rule_insert);
+ add_test ("/h-rule/insert-text-after", test_h_rule_insert_text_after);
#undef add_test
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 299e87a..de628cd 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -9837,6 +9837,117 @@ return_pressed_in_image_wrapper (EEditorPage *editor_page)
return TRUE;
}
+static gboolean
+return_pressed_after_h_rule (EEditorPage *editor_page)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMDocumentFragment *fragment;
+ WebKitDOMElement *selection_marker;
+ WebKitDOMNode *node, *block, *clone, *hr, *insert_before = NULL;
+ EEditorHistoryEvent *ev = NULL;
+ EEditorUndoRedoManager *manager;
+
+ g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), FALSE);
+
+ document = e_editor_page_get_document (editor_page);
+
+ if (!e_editor_dom_selection_is_collapsed (editor_page))
+ return FALSE;
+
+ e_editor_dom_selection_save (editor_page);
+
+ manager = e_editor_page_get_undo_redo_manager (editor_page);
+
+ if (e_editor_undo_redo_manager_is_operation_in_progress (manager)) {
+ selection_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
+
+ hr = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (selection_marker));
+ hr = webkit_dom_node_get_next_sibling (hr);
+ node = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (selection_marker));
+ if (node && !WEBKIT_DOM_IS_HTML_BR_ELEMENT (node) &&
+ !WEBKIT_DOM_IS_HTML_HR_ELEMENT (hr)) {
+ e_editor_dom_selection_restore (editor_page);
+ return FALSE;
+ }
+
+ insert_before = webkit_dom_node_get_next_sibling (hr);
+ } else {
+ selection_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+
+ node = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (selection_marker));
+ hr = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (selection_marker));
+ if (!WEBKIT_DOM_IS_HTML_BODY_ELEMENT (node) ||
+ !WEBKIT_DOM_IS_HTML_HR_ELEMENT (hr)) {
+ e_editor_dom_selection_restore (editor_page);
+ return FALSE;
+ }
+
+ insert_before = WEBKIT_DOM_NODE (selection_marker);
+
+ ev = g_new0 (EEditorHistoryEvent, 1);
+ ev->type = HISTORY_INPUT;
+
+ e_editor_dom_selection_get_coordinates (editor_page,
+ &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 = webkit_dom_node_get_previous_sibling (hr);
+
+ clone = webkit_dom_node_clone_node_with_error (block, FALSE, NULL);
+
+ 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 (hr), clone, insert_before, NULL);
+
+ dom_remove_selection_markers (document);
+
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (clone),
+ WEBKIT_DOM_NODE (
+ dom_create_selection_marker (document, TRUE)),
+ NULL);
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (clone),
+ WEBKIT_DOM_NODE (
+ dom_create_selection_marker (document, FALSE)),
+ NULL);
+
+ if (ev) {
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (fragment),
+ webkit_dom_node_clone_node_with_error (clone, TRUE, NULL),
+ NULL);
+
+ e_editor_dom_selection_get_coordinates (editor_page,
+ &ev->after.start.x,
+ &ev->after.start.y,
+ &ev->after.end.x,
+ &ev->after.end.y);
+
+ ev->data.fragment = fragment;
+
+ e_editor_undo_redo_manager_insert_history_event (manager, ev);
+ }
+
+ e_editor_page_emit_content_changed (editor_page);
+
+ e_editor_dom_selection_restore (editor_page);
+
+ return TRUE;
+}
+
gboolean
e_editor_dom_return_pressed_in_empty_list_item (EEditorPage *editor_page)
{
@@ -10069,6 +10180,9 @@ e_editor_dom_key_press_event_process_return_key (EEditorPage *editor_page)
if (return_pressed_in_image_wrapper (editor_page))
return TRUE;
+ if (return_pressed_after_h_rule (editor_page))
+ return TRUE;
+
return FALSE;
}
diff --git a/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
b/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
index 2533ad7..8a40846 100644
--- a/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
+++ b/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
@@ -1258,9 +1258,10 @@ undo_redo_hrule_dialog (EEditorPage *editor_page,
}
}
- if (undo)
+ if (undo) {
+ dom_remove_selection_markers (document);
restore_selection_to_history_event_state (editor_page, event->before);
- else
+ } else
e_editor_dom_selection_restore (editor_page);
}
@@ -1846,6 +1847,36 @@ undo_return_in_empty_list_item (EEditorPage *editor_page,
e_editor_dom_selection_restore (editor_page);
}
+static gboolean
+undo_return_press_after_h_rule (EEditorPage *editor_page,
+ EEditorHistoryEvent *event)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMElement *selection_start_marker, *block;
+ WebKitDOMNode *node;
+
+ document = e_editor_page_get_document (editor_page);
+
+ e_editor_dom_selection_save (editor_page);
+
+ selection_start_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+
+ block = get_parent_block_element (WEBKIT_DOM_NODE (selection_start_marker));
+ node = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE( block));
+
+ if (!webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (selection_start_marker)) &&
+ WEBKIT_DOM_IS_HTML_HR_ELEMENT (node)) {
+
+ remove_node_if_empty (WEBKIT_DOM_NODE (block));
+ restore_selection_to_history_event_state (editor_page, event->before);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
undo_input (EEditorUndoRedoManager *manager,
EEditorPage *editor_page,
@@ -1863,6 +1894,16 @@ undo_input (EEditorUndoRedoManager *manager,
restore_selection_to_history_event_state (editor_page, event->after);
+ /* Undoing Return press after the HR element */
+ if (e_editor_page_get_html_mode (editor_page) &&
+ g_object_get_data (G_OBJECT (event->data.fragment), "history-return-key")) {
+ if (undo_return_press_after_h_rule (editor_page, event)) {
+ g_object_unref (dom_window);
+ g_object_unref (dom_selection);
+ return;
+ }
+ }
+
webkit_dom_dom_selection_modify (dom_selection, "extend", "left", "character");
if (e_editor_dom_selection_is_citation (editor_page)) {
/* Post processing of quoted text in body_input_event_cb needs to be called. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]