Skip to content

Commit

Permalink
Graphics: Fix deletion of images by id not working for images with no…
Browse files Browse the repository at this point in the history
… placements
  • Loading branch information
kovidgoyal committed Dec 24, 2024
1 parent 6103224 commit 24a195c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Detailed list of changes

- Cursor trails: Fix pure vertical movement sometimes not triggering a trail and holding down a key in nvim causing the trail to be glitchy (:pull:`8152`, :pull:`8153`)

- Graphics: Fix deletion of images by id not working for images with no placements

0.38.0 [2024-12-15]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
17 changes: 17 additions & 0 deletions kitty/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,23 @@ static void
handle_delete_command(GraphicsManager *self, const GraphicsCommand *g, Cursor *c, bool *is_dirty, CellPixelSize cell) {
if (self->currently_loading.loading_for.image_id) free_load_data(&self->currently_loading);
GraphicsCommand d;
if (!g->placement_id) {
// special case freeing of images with no refs by id or number as
// filter_refs doesnt handle this
Image *img = NULL;
switch(g->delete_action) {
case 'I': img = img_by_client_id(self, g->id); break;
case 'N': img = img_by_client_number(self, g->image_number); break;
case 'R': {
for (image_map_itr ii = vt_first(&self->images_by_internal_id); !vt_is_end(ii); ) {
img = ii.data->val;
if (id_range_filter_func(NULL, img, g, cell) && !vt_size(&img->refs_by_internal_id)) ii = remove_image_itr(self, ii);
else ii = vt_next(ii);
}
} img = NULL; break;
}
if (img && !vt_size(&img->refs_by_internal_id)) remove_image(self, img);
}
switch (g->delete_action) {
#define I(u, data, func) filter_refs(self, data, g->delete_action == u, func, cell, false, true); *is_dirty = true; break
#define D(l, u, data, func) case l: case u: I(u, data, func)
Expand Down
15 changes: 13 additions & 2 deletions kitty_tests/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ def put_image(screen, w, h, **kw):
iid += 1
imgid = kw.pop('id', None) or iid
no_id = kw.pop('no_id', False)
a = kw.pop('a', 'T')
if no_id:
cmd = 'a=T,f=24,s=%d,v=%d,%s' % (w, h, put_cmd(**kw))
cmd = f'a={a},f=24,s=%d,v=%d,%s' % (w, h, put_cmd(**kw))
else:
cmd = 'a=T,f=24,i=%d,s=%d,v=%d,%s' % (imgid, w, h, put_cmd(**kw))
cmd = f'a={a},f=24,i=%d,s=%d,v=%d,%s' % (imgid, w, h, put_cmd(**kw))
data = b'x' * w * h * 3
res = send_command(screen, cmd, data)
return imgid, parse_response(res)
Expand Down Expand Up @@ -1051,6 +1052,16 @@ def delete(ac=None, **kw):
cmd += ',' + ','.join(f'{k}={v}' for k, v in kw.items())
send_command(s, cmd)

iid = put_image(s, cw, ch, a='t')[0]
self.ae(s.grman.image_count, 1)
delete('I', i=iid)
self.ae(s.grman.image_count, 0)
iid1 = put_image(s, cw, ch, a='t')[0]
iid2 = put_image(s, cw, ch, a='t')[0]
self.ae(s.grman.image_count, 2)
delete('R', x=iid1, y=iid2)
self.ae(s.grman.image_count, 0)

put_image(s, cw, ch)
delete()
self.ae(s.grman.image_count, 1)
Expand Down

0 comments on commit 24a195c

Please sign in to comment.