[evolution] Make sure there's a cursor located after document load of the HTML editor
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Make sure there's a cursor located after document load of the HTML editor
- Date: Thu, 18 Aug 2016 08:05:14 +0000 (UTC)
commit 811dd83807596f2599373bd1994036b9b4eeebb9
Author: Milan Crha <mcrha redhat com>
Date: Thu Aug 18 09:47:17 2016 +0200
Make sure there's a cursor located after document load of the HTML editor
It could happen that the E_CONTENT_EDITOR_INSERT_REPLACE_ALL made
the editor in a state where was no cursor placed in the body. This
affected mostly the unit tests of the HTML editor, but it should
not cause any issues in general.
.../web-extension/e-editor-web-extension.c | 41 ++++++++++++++++++++
1 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/modules/webkit-editor/web-extension/e-editor-web-extension.c
b/modules/webkit-editor/web-extension/e-editor-web-extension.c
index 38a2a5b..5f06110 100644
--- a/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -28,6 +28,12 @@
#include <webkit2/webkit-web-extension.h>
#include <camel/camel.h>
+#define WEBKIT_DOM_USE_UNSTABLE_API
+#include <webkitdom/WebKitDOMDocumentUnstable.h>
+#include <webkitdom/WebKitDOMDOMSelection.h>
+#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
+#undef WEBKIT_DOM_USE_UNSTABLE_API
+
#include "web-extensions/e-dom-utils.h"
#include "e-editor-page.h"
@@ -2423,6 +2429,37 @@ web_page_send_request_cb (WebKitWebPage *web_page,
}
static void
+web_page_document_loaded_cb (WebKitWebPage *web_page,
+ gpointer user_data)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMRange *range = NULL;
+ WebKitDOMDOMWindow *dom_window;
+ WebKitDOMDOMSelection *dom_selection;
+
+ g_return_if_fail (WEBKIT_IS_WEB_PAGE (web_page));
+
+ document = webkit_web_page_get_dom_document (web_page);
+ if (!document)
+ return;
+
+ dom_window = webkit_dom_document_get_default_view (document);
+ dom_selection = webkit_dom_dom_window_get_selection (dom_window);
+
+ /* Make sure there is a cursor located in the body after the document loads. */
+ if (!webkit_dom_dom_selection_get_anchor_node (dom_selection) &&
+ !webkit_dom_dom_selection_get_focus_node (dom_selection)) {
+ range = webkit_dom_document_caret_range_from_point (document, 0, 0);
+ webkit_dom_dom_selection_remove_all_ranges (dom_selection);
+ webkit_dom_dom_selection_add_range (dom_selection, range);
+ }
+
+ g_clear_object (&range);
+ g_clear_object (&dom_selection);
+ g_clear_object (&dom_window);
+}
+
+static void
web_page_created_cb (WebKitWebExtension *wk_extension,
WebKitWebPage *web_page,
EEditorWebExtension *extension)
@@ -2444,6 +2481,10 @@ web_page_created_cb (WebKitWebExtension *wk_extension,
g_signal_connect (
web_page, "send-request",
G_CALLBACK (web_page_send_request_cb), extension);
+
+ g_signal_connect (
+ web_page, "document-loaded",
+ G_CALLBACK (web_page_document_loaded_cb), NULL);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]