mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 11:35:48 +00:00
terminal: increaseCapacity should preserve dirty flag
This never caused any known issues, but it's a bug! `increaseCapacity` should produce a node with identical contents, just more capacity. We were forgetting to copy over the dirty flag. I looked back at `adjustCapacity` and it also didn't preserve the dirty flag so presumably downstream consumers have been handling this case manually. But, I think semantically it makes sense for `increaseCapacity` to preserve the dirty flag. This bug was found by AI (while I was doing another task). I fixed it and wrote the test by hand though.
This commit is contained in:
@@ -3045,6 +3045,9 @@ pub fn increaseCapacity(
|
||||
@panic("unexpected clone failure");
|
||||
};
|
||||
|
||||
// Preserve page-level dirty flag (cloneFrom only copies row data)
|
||||
new_page.dirty = page.dirty;
|
||||
|
||||
// Must not fail after this because the operations we do after this
|
||||
// can't be recovered.
|
||||
errdefer comptime unreachable;
|
||||
@@ -6942,6 +6945,37 @@ test "PageList increaseCapacity multi-page" {
|
||||
);
|
||||
}
|
||||
|
||||
test "PageList increaseCapacity preserves dirty flag" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
var s = try init(alloc, 2, 4, 0);
|
||||
defer s.deinit();
|
||||
|
||||
// Set page dirty flag and mark some rows as dirty
|
||||
const page = &s.pages.first.?.data;
|
||||
page.dirty = true;
|
||||
|
||||
const rows = page.rows.ptr(page.memory);
|
||||
rows[0].dirty = true;
|
||||
rows[1].dirty = false;
|
||||
rows[2].dirty = true;
|
||||
rows[3].dirty = false;
|
||||
|
||||
// Increase capacity
|
||||
const new_node = try s.increaseCapacity(s.pages.first.?, .styles);
|
||||
|
||||
// The page dirty flag should be preserved
|
||||
try testing.expect(new_node.data.dirty);
|
||||
|
||||
// Row dirty flags should be preserved
|
||||
const new_rows = new_node.data.rows.ptr(new_node.data.memory);
|
||||
try testing.expect(new_rows[0].dirty);
|
||||
try testing.expect(!new_rows[1].dirty);
|
||||
try testing.expect(new_rows[2].dirty);
|
||||
try testing.expect(!new_rows[3].dirty);
|
||||
}
|
||||
|
||||
test "PageList pageIterator single page" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
Reference in New Issue
Block a user