diff --git a/kitty/graphics.c b/kitty/graphics.c index 47f326b8b..df7a3e2b8 100644 --- a/kitty/graphics.c +++ b/kitty/graphics.c @@ -16,6 +16,7 @@ #include #include +#include #define REPORT_ERROR(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); } @@ -629,9 +630,9 @@ grman_scroll_images(GraphicsManager *self, int32_t amt, int32_t limit) { size_t i, j; if (self->image_count) { - for (i = self->image_count; i-- > 0; i--) { + for (i = self->image_count; i-- > 0;) { img = self->images + i; - for (j = img->refcnt; j-- > 0; j--) { + for (j = img->refcnt; j-- > 0;) { ref = img->refs + j; ref->start_row += amt; if (ref->start_row + (int32_t)ref->effective_num_rows < limit) { @@ -768,6 +769,10 @@ static PyMethodDef methods[] = { {NULL} /* Sentinel */ }; +static PyMemberDef members[] = { + {"image_count", T_UINT, offsetof(GraphicsManager, image_count), 0, "image_count"}, + {NULL}, +}; PyTypeObject GraphicsManager_Type = { PyVarObject_HEAD_INIT(NULL, 0) @@ -778,6 +783,7 @@ PyTypeObject GraphicsManager_Type = { .tp_doc = "GraphicsManager", .tp_new = new, .tp_methods = methods, + .tp_members = members, }; static PyMethodDef module_methods[] = { diff --git a/kitty_tests/graphics.py b/kitty_tests/graphics.py index 5c3a407cd..8b4d6ce81 100644 --- a/kitty_tests/graphics.py +++ b/kitty_tests/graphics.py @@ -208,3 +208,19 @@ class TestGraphics(BaseTest): rect_eq(l[1]['dest_rect'], -1, 1, -1 + dx, 1 - dy) self.ae(l[0]['group_count'], 1), self.ae(l[1]['group_count'], 1) self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 1) + + def test_gr_scroll(self): + cw, ch = 10, 20 + s, dx, dy, put_image, put_ref, layers, rect_eq = put_helpers(self, cw, ch) + put_image(s, 10, 20) # a one cell image at (0, 0) + self.ae(len(layers(s)), 1) + for i in range(s.lines): + s.index() + self.ae(len(layers(s)), 1), self.ae(s.grman.image_count, 1) + s.index() + self.ae(len(layers(s)), 0), self.ae(s.grman.image_count, 1) + for i in range(s.historybuf.ynum - 1): + s.index() + self.ae(s.grman.image_count, 1) + s.index() + self.ae(s.grman.image_count, 0)