commit 97cb21cdfaeff6052c984dd9a9bbe56f5e2deb60 from: Mark Jamsek via: Thomas Adam date: Tue Jul 12 08:00:21 2022 UTC tog: adjust view line offset when resizing hsplit Squish bug that can move the selection cursor offscreen when resizing horizontal splits due to bogus offset: $ TOG_VIEW_SPLIT_MODE=h tog # 80x24 22j return # open diff view in a hsplit tab # focus log (top) split 10+ # increase top split by 10 lines 22j return # open diff view in a hsplit F # toggle fullscreen diff view tab # focus log (parent) view in fullscreen *selection cursor will be off the bottom of the screen* ok stsp@ commit - 4fc71f3b760478d7300692fa227470174bf71bef commit + 97cb21cdfaeff6052c984dd9a9bbe56f5e2deb60 blob - 2e5fb20661bf53539d3543e78e7d989cee25bb15 blob + 8c414237565f6f896667f19527083e844f1331eb --- tog/tog.c +++ tog/tog.c @@ -931,6 +931,25 @@ view_resize(struct tog_view *view) view->cols = COLS; return NULL; +} + +static void +view_adjust_offset(struct tog_view *view, int n) +{ + if (n == 0) + return; + + if (view->parent && view->parent->offset) { + if (view->parent->offset + n >= 0) + view->parent->offset += n; + else + view->parent->offset = 0; + } else if (view->offset) { + if (view->offset - n >= 0) + view->offset -= n; + else + view->offset = 0; + } } static const struct got_error * @@ -965,6 +984,7 @@ view_resize_split(struct tog_view *view, int resize) } v->ncols = COLS; v->child->ncols = COLS; + view_adjust_offset(view, resize); err = view_init_hsplit(v, v->child->begin_y); if (err) return err;