"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mikhail <mp39590@gmail.com>
Subject:
search issues in tog after cursor movement
To:
gameoftrees@openbsd.org
Date:
Fri, 17 Jun 2022 21:21:14 +0300

Download raw body.

Thread
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?

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;
 	}