From b2ae1f73626bdd260b88c0cb60ba24a4e5c0fd55 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Wed, 14 Aug 2013 08:50:13 +0200
Subject: [PATCH] Allow to clear the inputbox on <esc> also if it's focused.

---
 src/command.c | 4 +++-
 src/keybind.c | 7 +++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/command.c b/src/command.c
index 0b6162e..cc70721 100644
--- a/src/command.c
+++ b/src/command.c
@@ -536,6 +536,8 @@ gboolean command_yank(const Arg *arg)
             text = gtk_clipboard_wait_for_text(SECONDARY_CLIPBOARD());
         }
         if (text) {
+            /* TODO should we show the full ynaked content with
+             * vb_set_input_text, wich migh get very large? */
             vb_echo_force(VB_MSG_NORMAL, false, "Yanked: %s", text);
             g_free(text);
 
@@ -544,7 +546,7 @@ gboolean command_yank(const Arg *arg)
 
         return false;
     }
-    /* use current arg.s a new clipboard content */
+    /* use current arg.s as new clipboard content */
     Arg a = {arg->i};
     if (arg->i & COMMAND_YANK_URI) {
         /* yank current url */
diff --git a/src/keybind.c b/src/keybind.c
index 86b2a6a..15cec61 100644
--- a/src/keybind.c
+++ b/src/keybind.c
@@ -249,11 +249,18 @@ static gboolean keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer is_i
     /* check for escape or modkeys or counts */
     if (IS_ESCAPE_KEY(keyval, state)) {
         vb.state.modkey = vb.state.count = 0;
+
+        /* remove focus from possible focused inputbox - this allows to clear
+         * the inputbox also if esc is pressed from inputbox for example after
+         * yanking some text or the result of the :shecllcmd */
+        gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview));
+
         /* switch to normal mode and clear the command line */
         vb_set_mode(VB_MODE_NORMAL, true);
 
         return true;
     } else if (GPOINTER_TO_INT(is_input) && keyval == GDK_Return) {
+        /* simulate the gtk entries activate callback */
         vb_input_activate();
         return true;
     }
-- 
2.20.1