From: Daniel Carl <danielcarl@gmx.de>
Date: Wed, 14 Jun 2017 21:21:28 +0000 (+0200)
Subject: Fix O after searching caused empty inputbox.
X-Git-Url: https://git.owens.tech/assets/editable-focus.html/assets/editable-focus.html/git?a=commitdiff_plain;h=a5e283370dd8b20d69dcddfd50f2e5b1f8f6be77;p=vimb.git

Fix O after searching caused empty inputbox.

In case a searching is active vimb is still in normal mode. So
'O'-keypress should write ':open URL' to the inputbox and switch vimb
into command mode. But during the switching of the modes, the already
written ':open ..' string was immediately overwritten by empty string.
So the user was left with cursor in empty inputbox.

Now the input is only cleared on stopping searching when a links was
fired during searching which is done in code during
WEBKIT_LOAD_COMMITTED event processing.
---

diff --git a/src/command.c b/src/command.c
index 28e9a12..c9168e5 100644
--- a/src/command.c
+++ b/src/command.c
@@ -31,6 +31,14 @@
 #include "history.h"
 #include "main.h"
 
+/**
+ * Start/perform/stop searching in webview.
+ *
+ * @commit: If TRUE, the search query is registered into register "/
+ *          In case searching is stopped the commit of value TRUE
+ *          is used to clear the inputbox if search is active. This is needed
+ *          in case a link is fired by <CR> on highlighted link.
+ */
 gboolean command_search(Client *c, const Arg *arg, bool commit)
 {
     WebKitFindController *fc;
@@ -46,8 +54,10 @@ gboolean command_search(Client *c, const Arg *arg, bool commit)
     if (arg->i == 0) {
         webkit_find_controller_search_finish(fc);
 
-        /* Clear the input only if the search is active. */
-        if (c->state.search.active) {
+        /* Clear the input only if the search is active and commit flag is
+         * set. This allows us to stop searching with and without cleaning
+         * inputbox */
+        if (commit && c->state.search.active) {
             vb_echo(c, MSG_NORMAL, FALSE, "");
         }
 
diff --git a/src/main.c b/src/main.c
index 90de537..c3fb8de 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1240,8 +1240,9 @@ static void on_webview_load_changed(WebKitWebView *webview,
             /* clear possible set marks */
             marks_clear(c);
 
-            /* Unset possible last search. */
-            command_search(c, &(Arg){0, NULL}, FALSE);
+            /* Unset possible last search. Use commit==TRUE to clear inputbox
+             * in case a link was fired from highlighted link. */
+            command_search(c, &(Arg){0, NULL}, TRUE);
 
             break;