From: Stefan Sperling Subject: Re: search issues in tog after cursor movement To: Mikhail Cc: gameoftrees@openbsd.org Date: Sat, 18 Jun 2022 18:19:28 +0200 On Fri, Jun 17, 2022 at 09:21:14PM +0300, Mikhail wrote: > While studying tog code, I found that search behaves a little bit > strange if you move cursor after you hit the match. > > To illustrate this open tog in got repository and search for 'foo' > (there are 3 matches), after you hit the last one, hit Home and then > 'n', it will say 'no more matches'. > > I think it's not what is expected by a user, at least mutt and editors > don't behave that way. > > Can you assess the following patch? Seems to work as expected for me. If nobody else has concerns then I think we should commit this. Thanks! > diff refs/heads/main refs/heads/search > blob - 8782d2289745425a1fdaecbd1edbcab6c230e7e6 > blob + a23ffa80af77e01eae15224e4b699b0e6e8a3020 > --- tog/tog.c > +++ tog/tog.c > @@ -2342,11 +2342,25 @@ search_next_log_view(struct tog_view *view) > entry = TAILQ_PREV(s->search_entry, > commit_queue_head, entry); > } else if (s->matched_entry) { > + int matched_idx = s->matched_entry->idx; > + int selected_idx = s->selected_entry->idx; > + > + /* > + * If user has moved cursor after we hit the match, position > + * from where we should continue search must be changed. > + */ > if (view->searching == TOG_SEARCH_FORWARD) > - entry = TAILQ_NEXT(s->matched_entry, entry); > + if (matched_idx > selected_idx) > + entry = TAILQ_NEXT(s->selected_entry, entry); > + else > + entry = TAILQ_NEXT(s->matched_entry, entry); > else > - entry = TAILQ_PREV(s->matched_entry, > - commit_queue_head, entry); > + if (matched_idx < selected_idx) > + entry = TAILQ_PREV(s->selected_entry, > + commit_queue_head, entry); > + else > + entry = TAILQ_PREV(s->matched_entry, > + commit_queue_head, entry); > } else { > entry = s->selected_entry; > } > >