Download raw body.
tog: key map to switch split mode
On 22-07-08 06:05pm, Stefan Sperling wrote: > On Sat, Jul 09, 2022 at 01:13:58AM +1000, Mark Jamsek wrote: > > On 22-07-08 10:32am, Stefan Sperling wrote: > > > On Thu, Jul 07, 2022 at 04:03:23PM +0200, Omar Polo wrote: > > > > Mark Jamsek <mark@jamsek.com> wrote: > > > > > Thanks, op! This fixes the problem for me. > > > > > > > > Yep, this works perfectly! ok for me. Thanks! > > > > > > Why switch on hsplits only while we are already in vpslit mode? > > > Wouldn't it make more sense to apply 'S' regardless of the currently > > > visible split configuration? I would expect it to behave like this: > > > > > > $ env | grep TOG > > > TOG_COLORS=1 > > > $ tog > > > press S > > > press Enter > > > diff view opens in hsplit in 80x24 terminal > > > > > > Such that 'S' always toggles between vsplit and hsplit, and hsplit is > > > always applied regardless of terminal size, and vsplit is only applied > > > under consideration of terminal size. > > > > > > Does this suggested behaviour cause a problem I am not seeing? > > > > I think this makes more sense and am not sure why I didn't think of this > > to begin with :) > > > > The below diff seems to implement the behaviour you suggest. > > More or less, though I would expect that in 80x24, an open hsplit view > would move into vsplit mode (and thus into the background) when I type > 'S'. With your patch, I can open tog and switch from vsplit to hsplit by > typing 'S', but then I cannot switch back to vsplit by typing 'S' again. > > Basically my idea is that 'S' switches from hsplit mode into vsplit mode, > and vice versa, and everything gets redrawn according to the rules of > the newly chosen mode. I misunderstood. Sorry! This diff _should_ now implement the desired behaviour :) diff refs/heads/main refs/heads/stash/switchsplit commit - 3c1dfe12b3f3eae6dc7ef4762772e849794296c5 commit + 5cec55df8f5fd70d1e7e5e19f4157f5ada2d89ce 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 - 310eb39a0776dd5fb11adc30d6c50fba6d7de13b blob + a5d90611997db9815fb80f198f864a0df35e90c5 --- tog/tog.c +++ tog/tog.c @@ -1114,10 +1114,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,26 +1126,27 @@ switch_split(struct tog_view *view) 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; + if (v->mode == TOG_VIEW_SPLIT_HRZN) v->mode = TOG_VIEW_SPLIT_VERT; - } else if (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) @@ -1165,14 +1163,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; } @@ -3091,11 +3094,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); } -- Mark Jamsek <fnc.bsdbox.org> GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68
tog: key map to switch split mode