From: NeilBrown Date: Fri, 4 Aug 2023 23:56:59 +0000 (+1000) Subject: renderline: change render-line:findxy to return the attributes X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=9d6f411aff45b5c4763c230164b83beb9a8ced05;p=edlib.git renderline: change render-line:findxy to return the attributes Rather then remembers the attributes to be collected later with a get:attr, return the attributes in a comm2 callback for immediate use. Signed-off-by: NeilBrown --- diff --git a/lib-renderline.c b/lib-renderline.c index 8bd6bfd7..f62ef646 100644 --- a/lib-renderline.c +++ b/lib-renderline.c @@ -44,7 +44,6 @@ struct render_list { struct rline_data { short prefix_len; - const char *xyattr; const char *cursattr; short curs_width; int scale; @@ -691,6 +690,7 @@ DEF_CMD(renderline) const char *xypos = NULL; const char *ret_xypos = NULL; const char *xyattr = NULL; + char *ret_xyattr = NULL; const char *cursattr = NULL; /* want_xypos becomes 2 when the pos is found */ int want_xypos = strcmp(ci->key, "render-line:findxy") == 0; @@ -770,10 +770,7 @@ DEF_CMD(renderline) * At that time ret_xypos is set, to be used to provide return value. * This might happen when y exceeds ypos, or we hit end-of-page. */ - if (want_xypos) { - free((void*)rd->xyattr); - rd->xyattr = NULL; - } + while (*line && y < p->h && !end_of_page) { if (mwidth <= 0) { @@ -798,7 +795,7 @@ DEF_CMD(renderline) posx = -1; if (want_xypos == 1 && xypos) { - rd->xyattr = xyattr ? strdup(xyattr) : NULL; + ret_xyattr = xyattr ? strdup(xyattr) : NULL; ret_xypos = xypos; want_xypos = 2; } @@ -1044,7 +1041,7 @@ DEF_CMD(renderline) &wrap_margin, NULL, &xypos, &xyattr, &cursattr); if (want_xypos == 1) { - rd->xyattr = xyattr ? strdup(xyattr) : NULL; + ret_xyattr = xyattr ? strdup(xyattr) : NULL; ret_xypos = xypos ?: line; want_xypos = 2; } @@ -1084,10 +1081,13 @@ DEF_CMD(renderline) free(r); } if (want_xypos) { + int pos = 0; if (ret_xypos) - return ret_xypos - line_start + 1; - else - return 1; + pos = ret_xypos - line_start; + comm_call(ci->comm2, "cb", ci->focus, pos, NULL, ret_xyattr); + free(ret_xyattr); + return pos + 1; + } else return end_of_page ? 2 : 1; } @@ -1104,8 +1104,6 @@ DEF_CMD(renderline_get) snprintf(buf, sizeof(buf), "%d", rd->prefix_len); else if (strcmp(ci->str, "curs_width") == 0) snprintf(buf, sizeof(buf), "%d", rd->curs_width); - else if (strcmp(ci->str, "xyattr") == 0) - val = rd->xyattr; else if (strcmp(ci->str, "width") == 0) snprintf(buf, sizeof(buf), "%d", rd->width); else if (strcmp(ci->str, "cursattr") == 0) @@ -1175,9 +1173,7 @@ DEF_CMD(renderline_close) { struct rline_data *rd = &ci->home->data; - free((void*)rd->xyattr); free((void*)rd->line); - rd->xyattr = NULL; return 1; } diff --git a/render-lines.c b/render-lines.c index 94072672..8633d1e9 100644 --- a/render-lines.c +++ b/render-lines.c @@ -182,21 +182,24 @@ static bool measure_line(struct pane *p safe, struct pane *focus safe, /* Returns offset of posx,posy */ static int find_xy_line(struct pane *p safe, struct pane *focus safe, - struct mark *mk safe, short posx, short posy) + struct mark *mk safe, short posx, short posy, + const char **xyattr) { struct pane *hp = mk->mdata; - int ret = 0; - - if (hp) { - ret = pane_call(hp, - "render-line:findxy", - focus, - -1, NULL, NULL, - 0, NULL, NULL, - posx - hp->x, posy - hp->y); - } + struct call_return cr; + + if (!hp) + return -1; + cr = pane_call_ret(all, hp, + "render-line:findxy", + focus, + -1, NULL, NULL, + 0, NULL, NULL, + posx - hp->x, posy - hp->y); + if (xyattr) + *xyattr = cr.s; /* xypos */ - return ret > 0 ? (ret - 1) : -1; + return cr.ret > 0 ? (cr.ret - 1) : -1; } static void draw_line(struct pane *p safe, struct pane *focus safe, @@ -1494,6 +1497,7 @@ DEF_CMD(render_lines_set_cursor) struct pane *focus = ci->focus; struct rl_data *rl = p->data; const char *action = ci->str; + const char *xyattr = NULL; struct mark *m; struct mark *m2 = NULL; struct xy cih; @@ -1523,7 +1527,7 @@ DEF_CMD(render_lines_set_cursor) action = NULL; cih.y = m->mdata->y; } - xypos = find_xy_line(p, focus, m, cih.x, cih.y); + xypos = find_xy_line(p, focus, m, cih.x, cih.y, &xyattr); if (xypos >= 0) { m2 = call_render_line_offset(focus, m, xypos); if (m2) { @@ -1535,10 +1539,9 @@ DEF_CMD(render_lines_set_cursor) } } if (m2) { - char *tag, *xyattr; + char *tag; - if (action) { - xyattr = pane_attr_get(m->mdata, "xyattr"); + if (action && xyattr) { tag = get_action_tag(action, xyattr); if (tag) { int x, y; @@ -1741,7 +1744,7 @@ DEF_CMD(render_lines_move_line) goto done; xypos = find_xy_line(p, focus, start, rl->target_x, - rl->target_y + start->mdata->y); + rl->target_y + start->mdata->y, NULL); if (xypos < 0) goto done;