From b0844c33fe7d04ea403b2d945824dee7dd339394 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sat, 28 Apr 2018 23:59:49 +0200 Subject: [PATCH] Shop the numbers of search matches in status bar. --- src/command.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/command.c b/src/command.c index 8c2600e..e851995 100644 --- a/src/command.c +++ b/src/command.c @@ -32,6 +32,9 @@ #include "history.h" #include "main.h" +static void on_found_text(WebKitFindController *fc, guint count, + Client *c); + /** * Start/perform/stop searching in webview. * @@ -63,7 +66,7 @@ gboolean command_search(Client *c, const Arg *arg, bool commit) vb_echo(c, MSG_NORMAL, FALSE, ""); } - c->state.search.active = FALSE; + c->state.search.active = FALSE; c->state.search.matches = 0; vb_statusbar_update(c); @@ -111,15 +114,15 @@ 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_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND | (direction > 0 ? WEBKIT_FIND_OPTIONS_NONE : WEBKIT_FIND_OPTIONS_BACKWARDS), G_MAXUINT); - c->state.search.active = TRUE; + c->state.search.active = TRUE; c->state.search.direction = direction; - /* TODO get the number of matches */ /* Skip first search because the first match is already * highlighted on search start. */ @@ -261,3 +264,14 @@ 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); + } +} -- 2.20.1