Commit dfc1d240864e4b31fed0d15b829dc86a45b808c5

Stefan Sperling 2018-05-10T14:44:11

improve selection behaviour for page-up/down scrolling

diff --git a/tog/tog.c b/tog/tog.c
index 7f8c1b8..d8bdfb1 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -611,9 +611,13 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
 				scroll_up(&first_displayed_entry, 1, &commits);
 				break;
 			case KEY_PPAGE:
+				if (TAILQ_FIRST(&commits) ==
+				    first_displayed_entry) {
+					selected = 0;
+					break;
+				}
 				scroll_up(&first_displayed_entry, LINES,
 				    &commits);
-				selected = 0;
 				break;
 			case 'j':
 			case KEY_DOWN:
@@ -631,13 +635,19 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
 				break;
 			case KEY_NPAGE:
 				nparents = num_parents(first_displayed_entry);
+				if (nparents < LINES - 1 &&
+				    selected < nparents - 1) {
+					selected = nparents - 1;
+					break;
+				}
 				err = scroll_down(&first_displayed_entry,
 				    MIN(nparents, LINES), last_displayed_entry,
 				    &commits, repo);
 				if (err)
 					goto done;
 				nparents = num_parents(first_displayed_entry);
-				selected = MIN(nparents, LINES) - 1;
+				if (selected > nparents)
+					selected = nparents - 1;
 				break;
 			case KEY_RESIZE:
 				if (selected > LINES)