commit 571ccd7300860975e644c75afcc015ad6c4d7ffd from: Mark Jamsek date: Tue Jul 19 04:23:37 2022 UTC tog: always request commits if log height is increased Includes style improvements prompted by stsp. Previously, we would only call request_log_commits() when terminal height is increased in a splitscreen view. This fixes the case when a log view with no children is resized that can lead to empty lines: $ tog # 80x24 23j # move down to the last commit *increase terminal height to ~30 lines then reduce back to 80x24* ~5j # move down to the _last_ commit *increase terminal height to ~33 lines* *new lines are empty* ok stsp@ commit - d2587c5f95c6edb51ccc8d4abfac838b58f3a463 commit + 571ccd7300860975e644c75afcc015ad6c4d7ffd blob - 97ac0690a9232815bb10bc4a237246e2ec53e069 blob + a1c09fab6d16d0c21514c895128b7972db68d6c6 --- tog/tog.c +++ tog/tog.c @@ -517,7 +517,7 @@ struct tog_view { int lines, cols; /* copies of LINES and COLS */ int nscrolled, offset; /* lines scrolled and hsplit line offset */ int ch, count; /* current keymap and count prefix */ - int resize; /* set when in a resize event */ + int resized; /* set when in a resize event */ int focussed; /* Only set on one parent or child view at a time. */ int dying; struct tog_view *parent; @@ -549,6 +549,7 @@ struct tog_view { const struct got_error *(*input)(struct tog_view **, struct tog_view *, int); const struct got_error *(*reset)(struct tog_view *); + const struct got_error *(*resize)(struct tog_view *, int); const struct got_error *(*close)(struct tog_view *); const struct got_error *(*search_start)(struct tog_view *); @@ -583,6 +584,7 @@ static const struct got_error *open_log_view(struct to static const struct got_error * show_log_view(struct tog_view *); static const struct got_error *input_log_view(struct tog_view **, struct tog_view *, int); +static const struct got_error *resize_log_view(struct tog_view *, int); static const struct got_error *close_log_view(struct tog_view *); static const struct got_error *search_start_log_view(struct tog_view *); static const struct got_error *search_next_log_view(struct tog_view *); @@ -731,13 +733,13 @@ view_splitscreen(struct tog_view *view) { const struct got_error *err = NULL; - if (!view->resize && view->mode == TOG_VIEW_SPLIT_HRZN) { + if (!view->resized && view->mode == TOG_VIEW_SPLIT_HRZN) { if (view->resized_y && view->resized_y < view->lines) view->begin_y = view->resized_y; else view->begin_y = view_split_begin_y(view->nlines); view->begin_x = 0; - } else if (!view->resize) { + } else if (!view->resized) { if (view->resized_x && view->resized_x < view->cols - 1 && view->cols > 119) view->begin_x = view->resized_x; @@ -768,8 +770,8 @@ view_fullscreen(struct tog_view *view) const struct got_error *err = NULL; view->begin_x = 0; - view->begin_y = view->resize ? view->begin_y : 0; - view->nlines = view->resize ? view->nlines : LINES; + view->begin_y = view->resized ? view->begin_y : 0; + view->nlines = view->resized ? view->nlines : LINES; view->ncols = COLS; view->lines = LINES; view->cols = COLS; @@ -873,25 +875,7 @@ view_resize(struct tog_view *view) view_splitscreen(view->child); show_panel(view->child->panel); - } - /* - * Request commits if terminal height was increased in a log - * view so we have enough commits loaded to populate the view. - */ - if (view->type == TOG_VIEW_LOG && dif > 0) { - struct tog_log_view_state *ts = &view->state.log; - - if (ts->commits.ncommits < ts->selected_entry->idx + - view->lines - ts->selected) { - view->nscrolled = ts->selected_entry->idx + - view->lines - ts->selected - - ts->commits.ncommits + dif; - err = request_log_commits(view); - if (err) - return err; - } } - /* * XXX This is ugly and needs to be moved into the above * logic but "works" for now and my attempts at moving it @@ -915,6 +899,12 @@ view_resize(struct tog_view *view) } else if (view->parent == NULL) ncols = COLS; + if (view->resize && dif > 0) { + err = view->resize(view, dif); + if (err) + return err; + } + if (wresize(view->window, nlines, ncols) == ERR) return got_error_from_errno("wresize"); if (replace_panel(view->panel, view->window) == ERR) @@ -927,6 +917,25 @@ view_resize(struct tog_view *view) view->cols = COLS; return NULL; +} + +static const struct got_error * +resize_log_view(struct tog_view *view, int increase) +{ + struct tog_log_view_state *s = &view->state.log; + const struct got_error *err = NULL; + int n = s->selected_entry->idx + view->lines - s->selected; + + /* + * Request commits to account for the increased + * height so we have enough to populate the view. + */ + if (s->commits.ncommits < n) { + view->nscrolled = n - s->commits.ncommits + increase + 1; + err = request_log_commits(view); + } + + return err; } static void @@ -962,7 +971,7 @@ view_resize_split(struct tog_view *view, int resize) if (!v->child || !view_is_splitscreen(v->child)) return NULL; - v->resize = v->child->resize = resize; /* lock for resize event */ + v->resized = v->child->resized = resize; /* lock for resize event */ if (view->mode == TOG_VIEW_SPLIT_HRZN) { int y = v->child->begin_y; @@ -1031,7 +1040,7 @@ view_resize_split(struct tog_view *view, int resize) else if (v->child->nscrolled) err = request_log_commits(v->child); - v->resize = v->child->resize = 0; + v->resized = v->child->resized = 0; return err; } @@ -2984,6 +2993,7 @@ open_log_view(struct tog_view *view, struct got_object view->show = show_log_view; view->input = input_log_view; + view->resize = resize_log_view; view->close = close_log_view; view->search_start = search_start_log_view; view->search_next = search_next_log_view;