From 322c724b77f794d98523c97c3fbe95f4e1d17d79 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 23 Jun 2023 12:17:22 +1000 Subject: [PATCH] lib-linefilter: always strip attributes from line before comparing. If the key is an attribute, tell the callback using ci->key=="attr" rather than the magic of -num2 == -1, which can get set by other doc:render-line functions. When the key is a line from doc:render-line, properly strip all attributes, both old and new style. Signed-off-by: NeilBrown --- lib-linefilter.c | 55 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/lib-linefilter.c b/lib-linefilter.c index 594e181b..dd68b923 100644 --- a/lib-linefilter.c +++ b/lib-linefilter.c @@ -43,17 +43,44 @@ struct rlcb { int cursor_offset; }; +static void strip_attrs(char *c safe) +{ + char *n = c; + if (*c == ack) { + for (; *c; c++) { + if (*c == ack || *c == etx) + continue; + if (*c != soh) { + *n++ = *c; + continue; + } + while (*c != stx) + c++; + } + } else { + for (; *c ; c++) { + if (*c == '<' && c[1] == '<') { + *n++ = *c++; + continue; + } + if (*c != '<') { + *n++ = *c; + continue; + } + while (*c != '>') + c++; + } + } + *n = 0; +} + DEF_CB(rlcb) { struct rlcb *cb = container_of(ci->comm, struct rlcb, c); char *c = ci->str ? strdup(ci->str) : NULL; - if (c && ci->num2 != -1) { - int i; - for (i = 0; c[i] ; i++) { - if (c[i] == '<') - memmove(c+i, c+i+1, strlen(c+i)); - } - } + if (c && strcmp(ci->key, "attr") != 0) + /* This is a rendered line so we need to strip out attrs. */ + strip_attrs(c); if (cb->fd == NULL) cb->cmp = 0; /* Don't compare, just save */ else if (c == NULL) @@ -151,10 +178,9 @@ DEF_CMD(render_filter_line) mark_to_mark(ci->mark, m); cb.cmp = 0; if (fd->attr) { - comm_call(&cb.c, "", ci->focus, + comm_call(&cb.c, "attr", ci->focus, NO_NUMERIC, NULL, - pane_mark_attr(ci->focus, m, fd->attr), - -1); + pane_mark_attr(ci->focus, m, fd->attr)); home_call(ci->home->parent, ci->key, ci->focus, NO_NUMERIC, m); } else @@ -187,10 +213,9 @@ DEF_CMD(render_filter_line) mark_to_mark(ci->mark, m); cb.cmp = 0; if (fd->attr) { - comm_call(&cb.c, "", ci->focus, + comm_call(&cb.c, "attr", ci->focus, NO_NUMERIC, NULL, - pane_mark_attr(ci->focus, m, fd->attr), - -1); + pane_mark_attr(ci->focus, m, fd->attr)); home_call(ci->home->parent, ci->key, ci->focus, NO_NUMERIC, m); } else @@ -236,9 +261,9 @@ static int do_filter_line_prev(struct filter_data *fd safe, cb.keep = !!savestr; cb.str = NULL; if (fd->attr) { - comm_call(&cb.c, "", focus, + comm_call(&cb.c, "attr", focus, NO_NUMERIC, NULL, - pane_mark_attr(focus, m, fd->attr), -1); + pane_mark_attr(focus, m, fd->attr)); } else { struct mark *m2 = mark_dup(m); -- 2.39.5