commit 969c159c1ef1e3ac2df93c76782f75e5136215eb from: Stefan Sperling date: Thu Jun 16 17:17:19 2022 UTC fix horizontal scrolling of unicode in tog diff view ok op@ commit - f7443f6606b9c7cb74ad4d52bc0a8f2128926f16 commit + 969c159c1ef1e3ac2df93c76782f75e5136215eb blob - ce1b254e1f4ae519df700e3c27df76b82dc3d652 blob + 34234f43c9ed0ca69cafef58339f81769b9fcc06 --- tog/tog.c +++ tog/tog.c @@ -3236,8 +3236,6 @@ draw_file(struct tog_view *view, const char *header) free(line); return got_ferror(s->f, GOT_ERR_IO); } - - view->maxx = MAX(view->maxx, linelen); tc = match_color(&s->colors, line); if (tc) @@ -3251,22 +3249,38 @@ draw_file(struct tog_view *view, const char *header) free(line); return err; } + view->maxx = MAX(view->maxx, width); } else { - err = format_line(&wline, &width, NULL, line, 0, - view->x + view->ncols, 0, view->x ? 1 : 0); + int skip; + + /* Set view->maxx based on full line length. */ + err = format_line(&wline, &width, NULL, line, + 0, INT_MAX, 0, view->x ? 1 : 0); if (err) { free(line); return err; } - if (view->x < width) - waddwstr(view->window, wline + view->x); + view->maxx = MAX(view->maxx, width); + + /* + * Get a new version of the line for display. + * This will be scrolled and/or trimmed in length. + */ free(wline); + err = format_line(&wline, &width, &skip, line, + view->x, view->ncols, 0, view->x ? 1 : 0); + if (err) { + free(line); + return err; + } + waddwstr(view->window, &wline[skip]); + free(wline); wline = NULL; } if (tc) wattr_off(view->window, COLOR_PAIR(tc->colorpair), NULL); - if (width - view->x <= view->ncols - 1) + if (width <= view->ncols - 1) waddch(view->window, '\n'); nprinted++; }