From: Stefan Sperling Subject: Re: tog: fix resize failure to populate log view commits To: Mark Jamsek Cc: gameoftrees@openbsd.org Date: Mon, 18 Jul 2022 17:02:29 +0200 On Mon, Jul 18, 2022 at 11:51:47PM +1000, Mark Jamsek wrote: > Or even better with the declaration :) Great, thanks! ok stsp@ > diff /home/mark/src/git/got-current > commit - d2587c5f95c6edb51ccc8d4abfac838b58f3a463 > path + /home/mark/src/git/got-current > blob - 97ac0690a9232815bb10bc4a237246e2ec53e069 > file + tog/tog.c > --- 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; > @@ -875,24 +877,6 @@ view_resize(struct tog_view *view) > 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 > * break either 'tab' or 'F' key maps in horizontal splits. > @@ -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) > @@ -929,6 +919,25 @@ view_resize(struct tog_view *view) > 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 > view_adjust_offset(struct tog_view *view, int n) > { > @@ -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; > > -- > Mark Jamsek > GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68