Don't skip first search match after committing search query.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 24 Feb 2014 09:06:47 +0000 (10:06 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 24 Feb 2014 09:12:12 +0000 (10:12 +0100)
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

index 0f34713..5133598 100644 (file)
@@ -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;