improve selection behaviour for page-up/down scrolling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
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)