]> git.neil.brown.name Git - edlib.git/commitdiff
renderline: allow Refresh to be handled.
authorNeilBrown <neil@brown.name>
Fri, 23 Jun 2023 05:47:03 +0000 (15:47 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:41 +0000 (17:51 +1000)
If the requested z depth (at attach time) is >= 0, then Refresh messages
will be sent.
They can now be handled.
The cursor pos for the refresh can now be set with renderline:set.
This ->num is only used for Refresh.

Signed-off-by: NeilBrown <neil@brown.name>
lib-renderline.c
render-lines.c

index 00f2b667960f5c3c4fe30661a311a9fc79eed214..b8fa299107ef45b71c8061e11f158e7c3a613bc0 100644 (file)
@@ -47,6 +47,7 @@ struct rline_data {
        short           curs_width;
        int             scale;
        const char      *line;
+       int             curspos;
 };
 
 enum {
@@ -625,9 +626,10 @@ static void set_xypos(struct render_list *rlst,
  * The marked-up text to be processed has already been provided with
  *   render-line:set.  It is in rd->line;
  * ->num is <0, or an index into ->str where the cursor is,
+ *   but is ignored for Refresh. which uses ->curspos for any cursor.
  *   and the x,y co-ords will be stored in p->cx,p->cy
- * If key is "render-line:draw", then send drawing commands, otherwise
- * just perform measurements.
+ * If key is "render-line:draw" or "Refresh" then send drawing commands,
+ * otherwise just perform measurements.
  * If key is "render-line:findxy", then only measure until the position
  *   in x,y is reached, then return an index into ->str of where we reached.
  *   Store the attributes active at the time so they can be fetched later.
@@ -638,9 +640,10 @@ DEF_CMD(renderline)
        struct rline_data *rd = p->data;
        struct pane *focus = ci->focus;
        const char *line = rd->line;
-       int dodraw = strcmp(ci->key, "render-line:draw") == 0;
+       int dodraw = (strcmp(ci->key, "render-line:draw") == 0 ||
+                     strcmp(ci->key, "Refresh") == 0);
        short posx;
-       short offset = ci->num;
+       short offset = strcmp(ci->key, "Refresh") == 0 ? rd->curspos : ci->num;
        int x = 0;
        int y = 0;
        const char *line_start;
@@ -1133,6 +1136,7 @@ DEF_CMD(renderline_set)
                rd->line = cvt(strdup(ci->str));
        else
                rd->line = NULL;
+       rd->curspos = ci->num;
        if (strcmp(rd->line ?:"", old ?:"") != 0 ||
            (old && xyscale.x != rd->scale)) {
                pane_damaged(ci->home, DAMAGED_REFRESH);
@@ -1164,6 +1168,7 @@ DEF_CMD(renderline_attach)
        if (!rl_map) {
                rl_map = key_alloc();
                key_add(rl_map, "render-line:draw", &renderline);
+               key_add(rl_map, "Refresh", &renderline);
                key_add(rl_map, "render-line:measure", &renderline);
                key_add(rl_map, "render-line:findxy", &renderline);
                key_add(rl_map, "get-attr", &renderline_get);
index e6a4ab8ee16f7954f7b0bfa78d0ffc655c74e6d6..f9e200476bebbd77b92aee5286262b67097e6701 100644 (file)
@@ -150,7 +150,7 @@ static void vmark_set(struct pane *p safe, struct mark *m safe, char *line safe)
        if (!m->mdata)
                m->mdata = call_ret(pane, "attach-renderline", p, -1);
        if (m->mdata)
-               pane_call(m->mdata, "render-line:set", p, 0, NULL, line);
+               pane_call(m->mdata, "render-line:set", p, -1, NULL, line);
 }
 
 static void vmark_invalidate(struct mark *m safe)