summaryrefslogtreecommitdiffstats
path: root/grid.c
diff options
context:
space:
mode:
authornicm <nicm>2019-07-16 10:30:56 +0000
committernicm <nicm>2019-07-16 10:30:56 +0000
commitb89f2f28bb5f21bfe836870d907ec6992acb5f28 (patch)
treea136da3c90b1bbc17d4d9abd12279c8b4b4b8386 /grid.c
parenteac055bfaf1b21b71d5fc79bc29a2810aa20085f (diff)
Fix grid clear code to correctly clear with the default background
colour rather than ending up with the used count higher than the total size, GitHub issue 1829.
Diffstat (limited to 'grid.c')
-rw-r--r--grid.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/grid.c b/grid.c
index cbff99e2..f33eef72 100644
--- a/grid.c
+++ b/grid.c
@@ -547,7 +547,7 @@ void
grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
{
struct grid_line *gl;
- u_int xx, yy;
+ u_int xx, yy, ox, sx;
if (nx == 0 || ny == 0)
return;
@@ -564,16 +564,20 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
for (yy = py; yy < py + ny; yy++) {
gl = &gd->linedata[yy];
- if (px + nx >= gd->sx && px < gl->cellused)
- gl->cellused = px;
- if (px > gl->cellsize && COLOUR_DEFAULT(bg))
- continue;
- if (px + nx >= gl->cellsize && COLOUR_DEFAULT(bg)) {
- gl->cellsize = px;
- continue;
+
+ sx = gd->sx;
+ if (sx > gl->cellsize)
+ sx = gl->cellsize;
+ ox = nx;
+ if (COLOUR_DEFAULT(bg)) {
+ if (px > sx)
+ continue;
+ if (px + nx > sx)
+ ox = sx - px;
}
- grid_expand_line(gd, yy, px + nx, 8); /* default bg first */
- for (xx = px; xx < px + nx; xx++)
+
+ grid_expand_line(gd, yy, px + ox, 8); /* default bg first */
+ for (xx = px; xx < px + ox; xx++)
grid_clear_cell(gd, xx, yy, bg);
}
}
@@ -1216,6 +1220,10 @@ grid_reflow(struct grid *gd, u_int sx)
struct grid_cell gc;
u_int yy, width, i, at, first;
+ /* Do not reflow to the same size. */
+ if (sx == gd->sx)
+ return;
+
/*
* Create a destination grid. This is just used as a container for the
* line data and may not be fully valid.