From c9745f7c124194d0368e1faf2271b14944ccaab7 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 15 Aug 2023 20:06:39 +1000 Subject: [PATCH] lib-renderline: various wrapping fixed. In particular, the subject line in notmuch summary lines wraps properly now. Signed-off-by: NeilBrown --- DOC/TODO.md | 6 ++--- display-x11-xcb.c | 4 +++ lib-renderline.c | 53 +++++++++++++++++++++++++--------------- python/module-notmuch.py | 2 +- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index f701aad5..f96f025b 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -12,13 +12,13 @@ the file. - [X] check formatting in x11 display. Wrap causes problems 474/476 of render-present.py and elsewhere -- [ ] check notmuch formatting. wrap-margin isn't right! +- [X] check notmuch formatting. wrap-margin isn't right! - [X] email display: image positioning is wrong. Maybe they don't get erased when moved. - [ ] remove tab_right hack by not requiring tail_length after final non-eol item -- [ ] resolve fixme around wrap_margin when splitting -- [ ] resolve fixme reguarding margin in find_curs +- [X] resolve fixme around wrap_margin when splitting +- [X] resolve fixme reguarding margin in find_curs - [ ] search "\brl([123]*|end)\b" replace "ri\1" does rlend -> rirlend - [ ] when should lib-renderline call measure_line? Only when asked? Or whenever content, width, scale change? diff --git a/display-x11-xcb.c b/display-x11-xcb.c index 4cf2aa11..dfa48ecc 100644 --- a/display-x11-xcb.c +++ b/display-x11-xcb.c @@ -383,8 +383,12 @@ static void parse_attrs( bg = word + 3; if (strcmp(word, "inverse") == 0) inv = True; + if (strcmp(word, "noinverse") == 0) + inv = False; if (strcmp(word, "underline") == 0) ul = True; + if (strcmp(word, "nounderline") == 0) + ul = False; } if (inv) { diff --git a/lib-renderline.c b/lib-renderline.c index 913417c6..95d4464e 100644 --- a/lib-renderline.c +++ b/lib-renderline.c @@ -731,7 +731,7 @@ static bool measure_line(struct pane *p safe, struct pane *focus safe, int offse if (ri->wrap && (wraprl == NULL || ri->wrap != wraprl->wrap)) wraprl = ri; if (ri->wrap_margin) - wrap_margin = ri->x; + wrap_margin = ri->x + xdiff; ri->wrap_x = wrap_margin; ri->x += xdiff; ri->y += ydiff; @@ -745,7 +745,7 @@ static bool measure_line(struct pane *p safe, struct pane *focus safe, int offse /* This doesn't fit here */ if (wraprl) { /* Move wraprl to next line and hide it unless it contains cursor */ - int xd = wraprl->x - wrap_margin; + int xd; struct render_item *wraprl2, *ri2; /* Find last ritem in wrap region.*/ @@ -753,8 +753,11 @@ static bool measure_line(struct pane *p safe, struct pane *focus safe, int offse wraprl2->next && wraprl2->next->wrap == wraprl->wrap ; wraprl2 = wraprl2->next) ; + wrap_margin = wraprl2->wrap_x; if (wraprl2->next) xd = wraprl2->next->x - wrap_margin; + else + xd = wraprl2->x - wrap_margin; if (offset >= 0 && offset >= wraprl->start && offset <= wraprl2->start + wraprl2->len) { @@ -779,23 +782,19 @@ static bool measure_line(struct pane *p safe, struct pane *focus safe, int offse for (ri2 = wraprl2->next ; ri2 && ri2 != ri->next; ri2 = ri2->next) { ri2->y += rd->line_height; ri2->x -= xd; + if (ri2->wrap_margin) + wrap_margin = ri2->x; + ri2->wrap_x = wrap_margin; } xdiff -= xd; ydiff += rd->line_height; wraprl = NULL; - continue; + if (ri->hidden || + ri->x + ri->width <= right_margin - rd->tail_length) + continue; } normal_wrap: - if (ri->x >= right_margin - rd->tail_length) { - /* This ri moves completely to next line */ - xdiff -= ri->x - wrap_margin; - ri->x = wrap_margin; - ydiff += rd->line_height; - ri->y += rd->line_height; - wraprl = NULL; - continue; - } - /* Need to split this ri into two or more pieces */ + /* Might need to split this ri into two or more pieces */ x = ri->x; splitpos = 0; while (1) { @@ -804,17 +803,31 @@ static bool measure_line(struct pane *p safe, struct pane *focus safe, int offse if (cr.ret == 2) /* Remainder fits now */ break; + if (cr.i == 0 && splitpos == 0) { + /* None of this fits here, move to next line */ + xdiff -= ri->x - wrap_margin; + ri->x = wrap_margin; + x = ri->x; + ydiff += rd->line_height; + ri->y += rd->line_height; + wraprl = NULL; + } + if (cr.i == 0) + /* Nothing fits and we already split - give up */ + break; /* re-measure the first part */ cr = do_measure(p, ri, splitpos, cr.i, right_margin - rd->tail_length - x); - ydiff += rd->line_height; - xdiff -= cr.x; // fixme where does wrap_margin fit in there - if (splitpos == 0) - xdiff -= ri->x; + xdiff -= cr.x; + if (splitpos == 0) { + xdiff -= ri->x - wrap_margin; + x = wrap_margin; + } splitpos += cr.i; - x = wrap_margin; + if (ri->split_cnt > 250) + break; add_split(ri, splitpos); } } @@ -878,7 +891,7 @@ static void draw_line(struct pane *p safe, struct pane *focus safe, int offset) if (ri->split_list && split < ri->split_cnt) { split += 1; do_draw(p, focus, ri, split, cpos, - rd->left_margin + rd->head_length, + ri->wrap_x, y); } } @@ -971,7 +984,7 @@ static struct xy find_curs(struct pane *p safe, int offset, const char **cursatt cr = do_measure(p, ri, st, offset - st, -1); if (split) - xy.x = cr.x; /* FIXME margin?? */ + xy.x = ri->wrap_x + cr.x; else xy.x = ri->x + cr.x; xy.y = ri->y + split * rd->line_height; diff --git a/python/module-notmuch.py b/python/module-notmuch.py index 4609d144..5206b1ba 100644 --- a/python/module-notmuch.py +++ b/python/module-notmuch.py @@ -841,7 +841,7 @@ class notmuch_query(edlib.Doc): " %TM-authors" + "%TM-size%TM-threadinfo<%TM-hilite>" + "%TM-flag" + - " " + + " " + "%TM-subject") self.add_notify(self.maindoc, "Notify:Tag") self.add_notify(self.maindoc, "Notify:Close") -- 2.39.5