From: Yoann Blein Date: Sat, 28 Oct 2017 16:22:53 +0000 (+0200) Subject: n/N restart the previous search if none is active X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=564c38e2ff78452c45a8a3ac9dc9b426e08f345e;p=vimb.git n/N restart the previous search if none is active vimb no longer ignores n/N if no search is active. Instead, it restarts a search with the same query that was used in the last search, just like Vim does. This is very convenient when searching for the same query in different pages. --- diff --git a/src/command.c b/src/command.c index dbb5b66..c147cec 100644 --- a/src/command.c +++ b/src/command.c @@ -22,6 +22,7 @@ * together. */ #include +#include #include "config.h" #ifdef FEATURE_QUEUE @@ -44,6 +45,7 @@ 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); @@ -62,7 +64,6 @@ gboolean command_search(Client *c, const Arg *arg, bool commit) } c->state.search.active = FALSE; - c->state.search.direction = 0; c->state.search.matches = 0; vb_statusbar_update(c); @@ -72,6 +73,14 @@ gboolean command_search(Client *c, const Arg *arg, bool commit) query = arg->s; count = abs(arg->i); + direction = arg->i > 0 ? 1 : -1; + + /* restart the last search if a search result is asked for and no + * search was active */ + if (!query && !c->state.search.active) { + query = c->state.search.last_query; + direction = c->state.search.direction; + } /* Only committed search strings adjust registers and are recorded in * history, intermediate strings (while using incsearch) don't. */ @@ -95,14 +104,21 @@ gboolean command_search(Client *c, const Arg *arg, bool commit) webkit_find_controller_search(fc, "", WEBKIT_FIND_OPTIONS_NONE, G_MAXUINT); } + if (!c->state.search.last_query) { + c->state.search.last_query = g_strdup(query); + } else if (strcmp(c->state.search.last_query, query)) { + g_free(c->state.search.last_query); + c->state.search.last_query = g_strdup(query); + } + webkit_find_controller_search(fc, query, WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND | - (arg->i > 0 ? WEBKIT_FIND_OPTIONS_NONE : WEBKIT_FIND_OPTIONS_BACKWARDS), + (direction > 0 ? WEBKIT_FIND_OPTIONS_NONE : WEBKIT_FIND_OPTIONS_BACKWARDS), G_MAXUINT); c->state.search.active = TRUE; - c->state.search.direction = arg->i > 0 ? 1 : -1; + c->state.search.direction = direction; /* TODO get the number of matches */ /* Skip first search because the first match is already diff --git a/src/main.c b/src/main.c index c440902..b56b17a 100644 --- a/src/main.c +++ b/src/main.c @@ -643,6 +643,10 @@ static void client_destroy(Client *c) vb.clients = c->next; } + if (c->state.search.last_query) { + g_free(c->state.search.last_query); + } + completion_cleanup(c); map_cleanup(c); register_cleanup(c); diff --git a/src/main.h b/src/main.h index de66fc5..7c51fac 100644 --- a/src/main.h +++ b/src/main.h @@ -176,6 +176,7 @@ struct State { gboolean active; /* indicate if there is a active search */ short direction; /* last direction 1 forward, -1 backward */ int matches; /* number of matching search results */ + char *last_query; /* last search query */ } search; };