add a tog helper function for scrolling up N lines
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 41 42 43 44 45 46 47
diff --git a/tog/tog.c b/tog/tog.c
index ca141f1..363c498 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -473,6 +473,27 @@ draw_commits(struct commit_queue_entry **last,
return err;
}
+static void
+scroll_up(struct commit_queue_entry **first_displayed_entry, int n,
+ struct commit_queue *commits)
+{
+ struct commit_queue_entry *entry;
+ int nscrolled = 0;
+
+ entry = TAILQ_FIRST(commits);
+ if (*first_displayed_entry == entry)
+ return;
+
+ entry = *first_displayed_entry;
+ while (entry && nscrolled < n) {
+ entry = TAILQ_PREV(entry, commit_queue, entry);
+ if (entry) {
+ *first_displayed_entry = entry;
+ nscrolled++;
+ }
+ }
+}
+
static const struct got_error *
show_log_view(struct got_object_id *start_id, struct got_repository *repo)
{
@@ -528,13 +549,7 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
selected--;
if (selected > 0)
break;
- /* scroll down if there are more children */
- entry = TAILQ_FIRST(&commits);
- if (first_displayed_entry == entry)
- break;
- first_displayed_entry =
- TAILQ_PREV(first_displayed_entry,
- commit_queue, entry);
+ scroll_up(&first_displayed_entry, 1, &commits);
break;
case 'j':
case KEY_DOWN: