From: NeilBrown Date: Wed, 30 Aug 2023 22:30:31 +0000 (+1000) Subject: renderline: fix "width" calculation. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=d5a15281530031bf439e21d532396c7f8c9b7406;p=edlib.git renderline: fix "width" calculation. "width" should be the sum of item widths without reference to wrapping or tabs. Maybe tabs should count, but -ve measures would not be useful, so just ignore them for now. This allows rtab in menu formats to work. Also don't include shift_left in the width. render-lines assumed it did (which it did, but now doesn't). Signed-off-by: NeilBrown --- diff --git a/lib-renderline.c b/lib-renderline.c index cc4dc6bd..515e4322 100644 --- a/lib-renderline.c +++ b/lib-renderline.c @@ -579,6 +579,7 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset break; } + rd->width = 0; for (ri = rd->content; ri; ri = ri->next) { ri->hidden = (ri->hide && ri->hide != offset_hide); if (ri->hidden) { @@ -613,6 +614,7 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset if (cr.i2 > rd->ascent) rd->ascent = cr.i2; ri->width = ri->eol ? 0 : cr.x; + rd->width += ri->width; if (ri->start <= offset && offset <= ri->start + ri->len) { cr = measure_str(p, "M", ri->attr); @@ -628,7 +630,6 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset */ x = left_margin - (shift_left > 0 ? shift_left : 0); y = rd->space_above * curs_height / 10; - rd->width = 0; for (ri = rd->content; ri; ri = ri->next) { int w, margin; struct render_item *ri2; @@ -643,8 +644,6 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset rd->curs_width); if (ri->eol) { /* EOL */ - if (x > rd->width) - rd->width = x; ri->x = x; x = 0; /* Don't include shift. probably not margin */ if (rd->line[ri->start]) diff --git a/render-lines.c b/render-lines.c index b6e86228..8538fc87 100644 --- a/render-lines.c +++ b/render-lines.c @@ -1081,7 +1081,7 @@ static int revalidate_start(struct rl_data *rl safe, */ cols = pane_attr_get_int(hp, "width", 0); while ((hp->cx < prefix_len - || cols + curs_width * 8 + curs_width < p->w) && + || (cols-rl->shift_left) + curs_width * 8 + curs_width < p->w) && rl->shift_left > 0 && shifts++ < 1000 && hp->cx + curs_width * 8 < p->w) {