From a1276b3cc37c01f2b0a89a769b71031cc25d0776 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Jul 2024 19:37:47 -0700 Subject: [PATCH] terminal/kitty: delete all images ignores virtual placements --- src/terminal/kitty/graphics_storage.zig | 34 +++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/terminal/kitty/graphics_storage.zig b/src/terminal/kitty/graphics_storage.zig index 82441a54e..bf8633c88 100644 --- a/src/terminal/kitty/graphics_storage.zig +++ b/src/terminal/kitty/graphics_storage.zig @@ -218,19 +218,27 @@ pub const ImageStorage = struct { cmd: command.Delete, ) void { switch (cmd) { - // TODO: virtual placeholders must not be deleted according to spec - .all => |delete_images| if (delete_images) { - // We just reset our entire state. - self.deinit(alloc, &t.screen); - self.* = .{ - .dirty = true, - .total_limit = self.total_limit, - }; - } else { - // Delete all our placements - self.clearPlacements(&t.screen); - self.placements.deinit(alloc); - self.placements = .{}; + .all => |delete_images| { + var it = self.placements.iterator(); + while (it.next()) |entry| { + // Skip virtual placements + switch (entry.value_ptr.location) { + .pin => {}, + .virtual => continue, + } + + // Deinit the placement and remove it + const image_id = entry.key_ptr.image_id; + entry.value_ptr.deinit(&t.screen); + self.placements.removeByPtr(entry.key_ptr); + if (delete_images) self.deleteIfUnused(alloc, image_id); + } + + if (delete_images) { + var image_it = self.images.iterator(); + while (image_it.next()) |kv| self.deleteIfUnused(alloc, kv.key_ptr.*); + } + self.dirty = true; },