From: Daniel Carl Date: Sun, 27 May 2018 22:18:34 +0000 (+0200) Subject: Fix wrong search hit count shown on prev/next. X-Git-Url: https://git.owens.tech/assets/static/git.owens.tech/assets/static/git.owens.tech/git?a=commitdiff_plain;h=6eec70212b0ae31911636f4f99a71fc6c9241d59;p=vimb.git Fix wrong search hit count shown on prev/next. If a search was done the shown number of search hits was right. But on case of stepping through the list, the match count was updated by 1. Now use the right signal "counted-matches" to get the real number of search hits independent from stepping through the list. --- diff --git a/src/command.c b/src/command.c index e851995..118881f 100644 --- a/src/command.c +++ b/src/command.c @@ -32,9 +32,6 @@ #include "history.h" #include "main.h" -static void on_found_text(WebKitFindController *fc, guint count, - Client *c); - /** * Start/perform/stop searching in webview. * @@ -45,19 +42,15 @@ static void on_found_text(WebKitFindController *fc, guint count, */ gboolean command_search(Client *c, const Arg *arg, bool commit) { - WebKitFindController *fc; const char *query; guint count; int direction; - fc = webkit_web_view_get_find_controller(c->webview); - g_assert(c); g_assert(arg); - g_assert(fc); if (arg->i == 0) { - webkit_find_controller_search_finish(fc); + webkit_find_controller_search_finish(c->finder); /* Clear the input only if the search is active and commit flag is * set. This allows us to stop searching with and without cleaning @@ -103,8 +96,8 @@ gboolean command_search(Client *c, const Arg *arg, bool commit) * on the page. Without this workaround the first selected match * depends on the most recent selection or caret position (even when * caret browsing is disabled). */ - if(commit) { - webkit_find_controller_search(fc, "", WEBKIT_FIND_OPTIONS_NONE, G_MAXUINT); + if (commit) { + webkit_find_controller_search(c->finder, "", WEBKIT_FIND_OPTIONS_NONE, G_MAXUINT); } if (!c->state.search.last_query) { @@ -114,8 +107,11 @@ gboolean command_search(Client *c, const Arg *arg, bool commit) c->state.search.last_query = g_strdup(query); } - g_signal_connect(fc, "found-text", G_CALLBACK(on_found_text), c); - webkit_find_controller_search(fc, query, + webkit_find_controller_count_matches(c->finder, query, + WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | + WEBKIT_FIND_OPTIONS_WRAP_AROUND, + G_MAXUINT); + webkit_find_controller_search(c->finder, query, WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND | (direction > 0 ? WEBKIT_FIND_OPTIONS_NONE : WEBKIT_FIND_OPTIONS_BACKWARDS), @@ -133,11 +129,11 @@ gboolean command_search(Client *c, const Arg *arg, bool commit) if (c->state.search.active) { if (arg->i * c->state.search.direction > 0) { while (count--) { - webkit_find_controller_search_next(fc); + webkit_find_controller_search_next(c->finder); } } else { while (count--) { - webkit_find_controller_search_previous(fc); + webkit_find_controller_search_previous(c->finder); } } } @@ -264,14 +260,3 @@ gboolean command_queue(Client *c, const Arg *arg) return res; } #endif - -static void on_found_text(WebKitFindController *fc, guint count, - Client *c) -{ - /* Avoid multiple useless status updates in case incsearch is enabled and - * we get the same count several times. */ - if (c->state.search.matches != count) { - c->state.search.matches = count; - vb_statusbar_update(c); - } -} diff --git a/src/main.c b/src/main.c index 38f19d5..b52e0a2 100644 --- a/src/main.c +++ b/src/main.c @@ -100,6 +100,7 @@ static void vimb_cleanup(void); #endif static void vimb_setup(void); static WebKitWebView *webview_new(Client *c, WebKitWebView *webview); +static void on_counted_matches(WebKitFindController *finder, guint count, Client *c); static void on_script_message_focus(WebKitUserContentManager *manager, WebKitJavascriptResult *res, gpointer data); static gboolean profileOptionArgFunc(const gchar *option_name, @@ -705,6 +706,9 @@ static Client *client_new(WebKitWebView *webview) /* webview */ c->webview = webview_new(c, webview); + c->finder = webkit_web_view_get_find_controller(c->webview); + g_signal_connect(c->finder, "counted-matches", G_CALLBACK(on_counted_matches), c); + c->page_id = webkit_web_view_get_page_id(c->webview); c->inspector = webkit_web_view_get_inspector(c->webview); @@ -1789,6 +1793,12 @@ static WebKitWebView *webview_new(Client *c, WebKitWebView *webview) return new; } +static void on_counted_matches(WebKitFindController *finder, guint count, Client *c) +{ + c->state.search.matches = count; + vb_statusbar_update(c); +} + static void on_script_message_focus(WebKitUserContentManager *manager, WebKitJavascriptResult *res, gpointer data) { diff --git a/src/main.h b/src/main.h index c6568bf..35681a1 100644 --- a/src/main.h +++ b/src/main.h @@ -219,6 +219,7 @@ struct Client { /* WebKitWebContext *webctx; */ /* not used atm, use webkit_web_context_get_default() instead */ GtkWidget *window, *input; WebKitWebView *webview; + WebKitFindController *finder; WebKitWebInspector *inspector; guint64 page_id; /* page id of the webview */ GtkTextBuffer *buffer;