From: Christian Weisgerber Subject: Re: tog: handle Home/End for log and diff views To: Jasper Lievisse Adriaanse Cc: gameoftrees@openbsd.org Date: Sat, 4 Sep 2021 12:33:40 +0200 Jasper Lievisse Adriaanse: > The 'End' handling for the log view was the trickiest because of the > way new commits are progressively discovered. I think the approach below > might be the quickest way we currently can do. Sorry for doing this so piecemeal, but I'd like to revise the jump to the end, too: > + case 'G': > + case KEY_END: { > + /* We don't know yet how many commits, so we're forced to > + * traverse them all. */ > + while (1) { > + if (s->thread_args.log_complete) > + break; > + > + s->thread_args.commits_needed++; > + trigger_log_thread(view, 1); > + } > + > + log_scroll_down(view, s->commits.ncommits); Since this doesn't account for the current position in the queue, it is really an upper bound. log_scroll_down(view, INT_MAX) would do the same. While traversing the queue is not a problem in practice, it is inelegant. > + s->selected = MIN(view->nlines - 2, s->commits.ncommits - 1); > + select_commit(s); > + break; > + } I would like to copy the approach from the tree and ref views: Start at the tail and traverse backwards as far as required. OK? diff refs/heads/main refs/heads/tweak blob - bca3ff788bde20700e3c2568236079a6d5be3970 blob + a61b2885188ca56c732c41d2f597ad00ab285533 --- tog/tog.c +++ tog/tog.c @@ -2387,7 +2387,8 @@ input_log_view(struct tog_view **new_view, struct tog_ struct tog_log_view_state *s = &view->state.log; struct tog_view *diff_view = NULL, *tree_view = NULL; struct tog_view *ref_view = NULL; - int begin_x = 0; + struct commit_queue_entry *entry; + int begin_x = 0, n; if (s->thread_args.load_all) { if (ch == KEY_BACKSPACE) @@ -2459,8 +2460,16 @@ input_log_view(struct tog_view **new_view, struct tog_ return trigger_log_thread(view, 0); } - log_scroll_down(view, s->commits.ncommits); - s->selected = MIN(view->nlines - 2, s->commits.ncommits - 1); + s->selected = 0; + entry = TAILQ_LAST(&s->commits.head, commit_queue_head); + for (n = 0; n < view->nlines - 1; n++) { + if (entry == NULL) + break; + s->first_displayed_entry = entry; + entry = TAILQ_PREV(entry, commit_queue_head, entry); + } + if (n > 0) + s->selected = n - 1; select_commit(s); break; } -- Christian "naddy" Weisgerber naddy@mips.inka.de