commit d9a7ab538a90fea0c81ac4c31fd196123baf4fd4 from: Mark Jamsek date: Mon Jul 11 14:25:33 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 - c0f61fa4e4ee942c16faa19eddc4b5362287b12c commit + d9a7ab538a90fea0c81ac4c31fd196123baf4fd4 blob - 69d159dd681696985e8930c154e65d4c007197bb blob + 03896eaec6ac32378d42edec34772acd9108d8bf --- tog/tog.c +++ tog/tog.c @@ -927,6 +927,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 * @@ -961,6 +980,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;