From d30a9c424d3e4afd8eada988e154c77937a3c59c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 20 Aug 2026 14:03:35 -0700 Subject: [PATCH] terminal: clear cursor pin garbage flag on screen reset --- src/terminal/Screen.zig | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 29305cbc6..1aba9c15a 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -397,11 +397,16 @@ pub fn reset(self: *Screen) void { self.pages.reset(); // The above reset preserves tracked pins so we can still use - // our cursor pin, which should be at the top-left already. + // our cursor pin, which should be at the top-left already. The + // reset marks every tracked pin as garbage, but we keep using + // this one at its new valid position, so clear the flag: copies + // of the cursor pin (e.g. for Kitty image placements) must not + // be born garbage. const cursor_pin: *PageList.Pin = self.cursor.page_pin; assert(cursor_pin.node == self.pages.pages.first.?); assert(cursor_pin.x == 0); assert(cursor_pin.y == 0); + cursor_pin.garbage = false; const cursor_rac = cursor_pin.rowAndCell(); self.cursor.deinit(self.alloc); self.cursor = .{ @@ -3806,6 +3811,23 @@ test "Screen forwards optional scrollback limits" { try testing.expect(!s.no_scrollback); } +test "Screen reset cursor pin is not garbage" { + const testing = std.testing; + const alloc = testing.allocator; + const io = testing.io; + + var s = try Screen.init(io, alloc, .{ .cols = 80, .rows = 24, .max_scrollback_bytes = 1000 }); + defer s.deinit(); + try s.testWriteString("hello, world"); + + // The page reset marks every tracked pin garbage but the screen + // keeps using the cursor pin, so it must come back clean: anything + // that copies it (e.g. Kitty image placements) would otherwise be + // born garbage and reaped. + s.reset(); + try testing.expect(!s.cursor.page_pin.garbage); +} + test "Screen read and write" { const testing = std.testing; const alloc = testing.allocator;