commit 7532ccdaec478d70fa5e613b9cda974c132faa6d from: Mark Jamsek date: Mon Jul 11 12:21:26 2022 UTC tog: make 'S' switch split mode irrespective of the view Always switch internal split state and redraw view according to the constraints of the new mode. suggested by and ok stsp@ commit - 5629093afb1a64a305b4f4fd4b47a18eb05c1480 commit + 7532ccdaec478d70fa5e613b9cda974c132faa6d blob - 39cc96c4b079ff1b9f5daafb5f0894e26c52df11 blob + 983fa45bf1aa8f912574f9bd29fd81395a4f9837 --- tog/tog.1 +++ tog/tog.1 @@ -81,11 +81,11 @@ Toggle fullscreen mode for a split-screen view. will automatically use split-screen views if the size of the terminal window is sufficiently large. .It Cm S -When in a split-screen view, +Switch the current split mode. .Nm -will switch to the alternate split mode. -If the current view is in a horizontal split and the terminal window is not -wide enough, the view will remain unchanged. +will also render the view in the new split mode. +If the terminal is not wide enough when switching to a vertical split, the +view will render in fullscreen. .It Cm - When in a split-screen view, decrease the size of the focussed split N increments (default: 1). blob - 87524f45815275ff098f65c61e350b793d15fe32 blob + a46cb65fd55714965d1a709355fc9f76db13c9f4 --- tog/tog.c +++ tog/tog.c @@ -1115,10 +1115,7 @@ view_search_start(struct tog_view *view) return NULL; } -/* - * If view is a parent or child view and is currently in a splitscreen, switch - * to the alternate split. If in a hsplit and LINES < 120, don't vsplit. - */ +/* Switch split mode. If view is a parent or child, draw the new splitscreen. */ static const struct got_error * switch_split(struct tog_view *view) { @@ -1129,27 +1126,28 @@ switch_split(struct tog_view *view) v = view->parent; else v = view; - - if (!v->child || !view_is_splitscreen(v->child)) - return NULL; - if (v->mode == TOG_VIEW_SPLIT_HRZN && v->cols < 120) - return NULL; - if (!v->mode || v->mode == TOG_VIEW_SPLIT_HRZN) { - v->child->nscrolled = LINES - v->child->nlines; - v->mode = TOG_VIEW_SPLIT_VERT; - } else if (v->mode == TOG_VIEW_SPLIT_VERT) + if (v->mode == TOG_VIEW_SPLIT_HRZN) + v->mode = TOG_VIEW_SPLIT_VERT; + else v->mode = TOG_VIEW_SPLIT_HRZN; + if (!v->child) + return NULL; + else if (v->mode == TOG_VIEW_SPLIT_VERT && v->cols < 120) + v->mode = TOG_VIEW_SPLIT_NONE; + view_get_split(v, &v->child->begin_y, &v->child->begin_x); if (v->mode == TOG_VIEW_SPLIT_HRZN && v->child->resized_y) v->child->begin_y = v->child->resized_y; - if (v->mode == TOG_VIEW_SPLIT_VERT && v->child->resized_x) + else if (v->mode == TOG_VIEW_SPLIT_VERT && v->child->resized_x) v->child->begin_x = v->child->resized_x; + if (v->mode == TOG_VIEW_SPLIT_HRZN) { v->ncols = COLS; v->child->ncols = COLS; + v->child->nscrolled = LINES - v->child->nlines; err = view_init_hsplit(v, v->child->begin_y); if (err) @@ -1166,14 +1164,19 @@ switch_split(struct tog_view *view) if (err) return err; - if (v->mode == TOG_VIEW_SPLIT_HRZN) + if (v->mode == TOG_VIEW_SPLIT_NONE) + v->mode = TOG_VIEW_SPLIT_VERT; + if (v->mode == TOG_VIEW_SPLIT_HRZN) { + err = offset_selection_down(v); err = offset_selection_down(v->child); - else if (v->mode == TOG_VIEW_SPLIT_VERT) { - if (v->type == TOG_VIEW_LOG) - err = request_log_commits(v); - else if (v->child->type == TOG_VIEW_LOG) - err = request_log_commits(v->child); + } else { + offset_selection_up(v); + offset_selection_up(v->child); } + if (v->type == TOG_VIEW_LOG) + err = request_log_commits(v); + else if (v->child->type == TOG_VIEW_LOG) + err = request_log_commits(v->child); return err; } @@ -3118,11 +3121,15 @@ view_get_split(struct tog_view *view, int *y, int *x) if (view->mode == TOG_VIEW_SPLIT_HRZN) { if (view->child && view->child->resized_y) *y = view->child->resized_y; + else if (view->resized_y) + *y = view->resized_y; else *y = view_split_begin_y(view->lines); - } else { + } else if (view->mode == TOG_VIEW_SPLIT_VERT) { if (view->child && view->child->resized_x) *x = view->child->resized_x; + else if (view->resized_x) + *x = view->resized_x; else *x = view_split_begin_x(view->begin_x); }