commit cbb0c8d7953cebb583b29d56dc27f83a38924411 from: Mark Jamsek date: Fri Aug 12 12:49:37 2022 UTC tog: fix log 'd' keymap when last commit is displayed When at the end of the log view such that the currently selected line is greater than nlines/2, add--don't assign--the page down value to the selected index so we don't jump up when the user expects tog to scroll down. While here, rework log page down logic for a smoother UX in horizontal split mode by moving the selection cursor down rather than scrolling when 'd' or 'f' is entered if the last commit is already on screen. ok stsp@ commit - d30ab56fff40b038af410d963b66e866a8e4e528 commit + cbb0c8d7953cebb583b29d56dc27f83a38924411 blob - 79bd77c80f7773fd9a6bd7e5f5cfeb69ff90f91c blob + 6ec38b4f4fb702fe582846031bfbd562ee40349a --- tog/tog.c +++ tog/tog.c @@ -2238,7 +2238,7 @@ draw_commits(struct tog_view *view) const struct got_error *err = NULL; struct tog_log_view_state *s = &view->state.log; struct commit_queue_entry *entry = s->selected_entry; - const int limit = view->nlines; + int limit = view->nlines; int width; int ncommits, author_cols = 4; char *id_str = NULL, *header = NULL, *ncommits_str = NULL; @@ -2246,6 +2246,9 @@ draw_commits(struct tog_view *view) wchar_t *wline; struct tog_color *tc; static const size_t date_display_cols = 12; + + if (view_is_hsplit_top(view)) + --limit; /* account for border */ if (s->selected_entry && !(view->searching && view->search_next_done == 0)) { @@ -3161,15 +3164,8 @@ static const struct got_error * log_move_cursor_down(struct tog_view *view, int page) { struct tog_log_view_state *s = &view->state.log; - struct commit_queue_entry *first; const struct got_error *err = NULL; - first = s->first_displayed_entry; - if (first == NULL) { - view->count = 0; - return NULL; - } - if (s->thread_args.log_complete && s->selected_entry->idx >= s->commits.ncommits - 1) return NULL; @@ -3192,13 +3188,12 @@ log_move_cursor_down(struct tog_view *view, int page) s->commits.ncommits - s->selected_entry->idx - 1)); s->selected = MIN(view->nlines - 2, s->commits.ncommits - 1); } else { - err = log_scroll_down(view, page); - if (err) - return err; - if (first == s->first_displayed_entry && s->selected < - MIN(view->nlines - 2, s->commits.ncommits - 1)) { - s->selected = MIN(s->commits.ncommits - 1, page); - } + if (s->last_displayed_entry->idx == s->commits.ncommits - 1 && + s->thread_args.log_complete) + s->selected += MIN(page, + s->commits.ncommits - s->selected_entry->idx - 1); + else + err = log_scroll_down(view, page); } if (err) return err;