Fixed regression against 112-editable-focus.html test (#197).
authorDaniel Carl <danielcarl@gmx.de>
Sun, 5 Apr 2015 21:43:49 +0000 (23:43 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 5 Apr 2015 21:43:49 +0000 (23:43 +0200)
src/dom.c
src/main.c

index 39695f5..9757704 100644 (file)
--- a/src/dom.c
+++ b/src/dom.c
@@ -32,9 +32,24 @@ static Element *get_active_element(Document *doc);
 
 void dom_check_auto_insert(WebKitWebView *view)
 {
+    Element *active;
     HtmlElement *element;
     Document *doc = webkit_web_view_get_dom_document(view);
 
+    /* FIrst check for current active element that bocomes focused before we
+     * could add the evnet observers. */
+    active = get_active_element(doc);
+    if (!vb.config.strict_focus) {
+        auto_insert(active);
+    } else if (vb.mode->id != 'i') {
+        /* If strict-focus is enabled and the editable element becomes focus,
+         * we explicitely remove the focus. But only if vim isn't in input
+         * mode at the time. This prevents from leaving input mode that was
+         * started by user interaction like click to editable element, or the
+         * gi normal mode command. */
+        webkit_dom_element_blur(active);
+    }
+
     element = webkit_dom_document_get_body(doc);
     if (!element) {
         element = WEBKIT_DOM_HTML_ELEMENT(webkit_dom_document_get_document_element(doc));
@@ -216,17 +231,8 @@ static gboolean editable_blur_cb(Element *element, Event *event)
 
 static gboolean editable_focus_cb(Element *element, Event *event)
 {
-    EventTarget *target = webkit_dom_event_get_target(event);
-    if (!vb.config.strict_focus) {
-        auto_insert((Element*)target);
-    } else if (vb.mode->id != 'i') {
-        /* If strict-focus is enabled and the editable element becomes focus,
-         * we explicitely remove the focus. But only if vim isn't in input
-         * mode at the time. This prevents from leaving input mode that was
-         * started by user interaction like click to editable element, or the
-         * gi normal mode command. */
-        webkit_dom_element_blur((Element*)target);
-    }
+    auto_insert((Element*)webkit_dom_event_get_target(event));
+
     return false;
 }
 
index b92d650..7f7168a 100644 (file)
@@ -763,7 +763,6 @@ static void webview_load_status_cb(WebKitWebView *view, GParamSpec *pspec)
             if (vb.mode->id == 'i') {
                 vb_enter('n');
             }
-            dom_check_auto_insert(view);
             break;
 
         case WEBKIT_LOAD_FINISHED:
@@ -777,6 +776,7 @@ static void webview_load_status_cb(WebKitWebView *view, GParamSpec *pspec)
             update_title();
 
             if (strncmp(uri, "about:", 6)) {
+                dom_check_auto_insert(view);
                 history_add(HISTORY_URL, uri, webkit_web_view_get_title(view));
             }
             break;