commit - 6e210706a4224007cf266b48c28e5a54e8279589
commit + c0c4acc88418ca34083144bd4feeb1c4001fc092
blob - 915bc83532c216505a96c19f3ac75ac031f66b87
blob + 66c10afc613515bfc9122f54ffacf6671ce45f67
--- tog/tog.c
+++ tog/tog.c
const struct got_error *(*search_start)(struct tog_view *);
const struct got_error *(*search_next)(struct tog_view *);
+ int search_started;
int searching;
#define TOG_SEARCH_FORWARD 1
#define TOG_SEARCH_BACKWARD 2
const struct got_error *err = NULL;
char pattern[1024];
int ret;
+
+ if (view->search_started) {
+ regfree(&view->regex);
+ view->searching = 0;
+ memset(&view->regmatch, 0, sizeof(view->regmatch));
+ }
+ view->search_started = 0;
if (view->nlines < 1)
return NULL;
noecho();
if (ret == ERR)
return NULL;
-
- if (view->searching) {
- regfree(&view->regex);
- view->searching = 0;
- }
if (regcomp(&view->regex, pattern, REG_EXTENDED | REG_NEWLINE) == 0) {
err = view->search_start(view);
regfree(&view->regex);
return err;
}
+ view->search_started = 1;
view->searching = TOG_SEARCH_FORWARD;
view->search_next_done = 0;
view->search_next(view);
break;
case 'N':
case 'n':
- if (view->search_next) {
+ if (view->search_started && view->search_next) {
view->searching = (ch == 'n' ?
TOG_SEARCH_FORWARD : TOG_SEARCH_BACKWARD);
view->search_next_done = 0;