From 57711abd9fb230e722ac52df164aa79d4970cec9 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Thu, 13 Jun 2013 00:13:43 +0200
Subject: [PATCH] Fixed leaving input mode on load commit (#33).

If a page was loaded and text was typed into the inputbox, the input
mode was left on WEBKIT_LOAD_COMMITED. Now we keep in insert mode also if
the page loads to allow to type in a command into inputbox.

Moved modkey unset to keybind.c where the modkeys are set.
---
 src/keybind.c |  4 ++++
 src/main.c    | 13 ++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/keybind.c b/src/keybind.c
index 515cb7c..b98e6d7 100644
--- a/src/keybind.c
+++ b/src/keybind.c
@@ -245,6 +245,7 @@ static gboolean keypress_cb(WebKitWebView *webview, GdkEventKey *event)
 
     /* check for escape or modkeys or counts */
     if (IS_ESCAPE_KEY(keyval, state)) {
+        vb.state.modkey = vb.state.count = 0;
         /* switch to normal mode and clear the input box */
         vb_set_mode(VB_MODE_NORMAL, true);
 
@@ -275,6 +276,9 @@ static gboolean keypress_cb(WebKitWebView *webview, GdkEventKey *event)
         Keybind *keybind = (Keybind*)link->data;
         command_run(keybind->command, keybind->param);
 
+        vb.state.modkey = vb.state.count = 0;
+        vb_update_statusbar();
+
         return true;
     }
 
diff --git a/src/main.c b/src/main.c
index 4fc3921..fc84477 100644
--- a/src/main.c
+++ b/src/main.c
@@ -149,9 +149,6 @@ gboolean vb_load_uri(const Arg *arg)
         uri = g_strdup_printf("http://%s", path);
     }
 
-    /* change state to normal mode */
-    vb_set_mode(VB_MODE_NORMAL, false);
-
     if (arg->i == VB_TARGET_NEW) {
         guint i = 0;
         char *cmd[7], xid[64];
@@ -205,8 +202,6 @@ gboolean vb_set_clipboard(const Arg *arg)
  */
 gboolean vb_set_mode(Mode mode, gboolean clean)
 {
-    vb.state.modkey = vb.state.count  = 0;
-
     /* process only if mode has changed */
     if (vb.state.mode != mode) {
         /* leaf the old mode */
@@ -421,8 +416,12 @@ static void webview_load_status_cb(WebKitWebView *view, GParamSpec *pspec)
                 run_user_script(frame);
             }
 
-            /* status bar is updated by vb_set_mode */
-            vb_set_mode(VB_MODE_NORMAL , false);
+            if (vb.state.mode & VB_MODE_INSERT) {
+                /* status bar is updated by vb_set_mode */
+                vb_set_mode(VB_MODE_NORMAL, false);
+            } else {
+                vb_update_statusbar();
+            }
             vb_update_urlbar(uri);
 
             break;
-- 
2.20.1