]> git.neil.brown.name Git - edlib.git/commitdiff
renderline: fix "width" calculation.
authorNeilBrown <neil@brown.name>
Wed, 30 Aug 2023 22:30:31 +0000 (08:30 +1000)
committerNeilBrown <neil@brown.name>
Wed, 30 Aug 2023 22:57:10 +0000 (08:57 +1000)
"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 <neil@brown.name>
lib-renderline.c
render-lines.c

index cc4dc6bd51cef220e410efde8ddf4e628ecb1da9..515e432267c1ba9d2fee2a98c8b431989fd6290d 100644 (file)
@@ -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])
index b6e8622801843f1d33d99d5b6d0fa2ee08a961a6..8538fc87a59671aec59bd5320e6a1004bd6d3e0d 100644 (file)
@@ -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) {