diff --git a/src/draw.c b/src/draw.c index 7c9321476..b764294b6 100644 --- a/src/draw.c +++ b/src/draw.c @@ -673,7 +673,7 @@ draw_view_line(struct view *view, unsigned int lineno) ok = view->ops->draw(view, line, lineno); - if (ok && line->search_result && view->regex) + if (ok && line->search_result && *view->grep) draw_view_line_search_result(view, lineno); return ok; diff --git a/src/search.c b/src/search.c index 5105f3e6e..f7866208e 100644 --- a/src/search.c +++ b/src/search.c @@ -39,13 +39,14 @@ find_matches(struct view *view) /* Note, lineno is unsigned long so will wrap around in which case it * will become bigger than view->lines. */ for (lineno = 0; lineno < view->lines; lineno++) { - if (!view->ops->grep(view, &view->line[lineno])) + view->line[lineno].search_result = view->ops->grep(view, &view->line[lineno]); + + if (!view->line[lineno].search_result) continue; if (!realloc_unsigned_ints(&view->matched_line, view->matched_lines, 1)) return false; - view->line[lineno].search_result = true; view->matched_line[view->matched_lines++] = lineno; } @@ -82,6 +83,9 @@ setup_and_find_next(struct view *view, enum request request) if (regex_err != 0) { char buf[SIZEOF_STR] = "unknown error"; + /* Clear highlighted results. */ + redraw_view_from(view, 0); + regerror(regex_err, view->regex, buf, sizeof(buf)); return error("Search failed: %s", buf); }