From 0a28c145cea84e61717853852a854675b1075953 Mon Sep 17 00:00:00 2001 From: Daniel Carl <danielcarl@gmx.de> Date: Mon, 24 Feb 2014 10:06:47 +0100 Subject: [PATCH] Don't skip first search match after committing search query. If the user typed the search text into inputbox, the search started. After the search query was commited via <CR> the search went forward a match. But like in vim the first found match should keep the first one after the search query is commited. --- src/command.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/command.c b/src/command.c index 0f34713..5133598 100644 --- a/src/command.c +++ b/src/command.c @@ -33,16 +33,14 @@ gboolean command_search(const Arg *arg) { static short dir; /* last direction 1 forward, -1 backward*/ static char *query = NULL; -#ifdef FEATURE_SEARCH_HIGHLIGHT - static gboolean highlight = false; -#endif + static gboolean newsearch = true; gboolean forward; if (arg->i == 0) { #ifdef FEATURE_SEARCH_HIGHLIGHT webkit_web_view_unmark_text_matches(vb.gui.webview); - highlight = false; #endif + newsearch = true; return true; } @@ -57,24 +55,28 @@ gboolean command_search(const Arg *arg) if (query) { unsigned int count = abs(arg->i); + if (newsearch) { #ifdef FEATURE_SEARCH_HIGHLIGHT - if (!highlight) { /* highlight matches if the search is started new or continued * after switch to normal mode which calls this function with * COMMAND_SEARCH_OFF */ webkit_web_view_mark_text_matches(vb.gui.webview, query, false, 0); webkit_web_view_set_highlight_text_matches(vb.gui.webview, true); +#endif - /* mark the search as active */ - highlight = true; + newsearch = false; + /* skip first search because this is done during typing in ex + * mode, else the search wil mark the next match as active */ + if (count) { + count -= 1; + } } -#endif - do { + while (count--) { if (!webkit_web_view_search_text(vb.gui.webview, query, false, forward, true)) { break; } - } while (--count); + }; } return true; -- 2.20.1