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

This commit is contained in:
Kovid Goyal 2024-12-24 09:39:01 +05:30
parent 6103224a7d
commit 24a195c7c7
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 32 additions and 2 deletions

View file

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -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)

View file

@ -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)
@ -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)