PageList: preserve size.cols in adjustCapacity after column shrink

When columns shrink during resize-without-reflow, page.size.cols is
updated but page.capacity.cols retains the old larger value. When
adjustCapacity later runs (e.g., to expand style/grapheme storage),
it was creating a new page using page.capacity which has the stale
column count, causing size.cols to revert to the old value.

This caused a crash in render.zig where an assertion checks that
page.size.cols matches PageList.cols.

Fix by explicitly copying page.size.cols to the new page after
creation, matching how size.rows is already handled.

Amp-Thread-ID: https://ampcode.com/threads/T-976bc49a-7bfd-40bd-bbbb-38f66fc925ff
Co-authored-by: Amp <amp@ampcode.com>
pull/9761/head
Tim Culverhouse 2025-11-30 08:25:04 -06:00 committed by Mitchell Hashimoto
parent 73be3abf00
commit a58e33c06b
1 changed files with 35 additions and 0 deletions

View File

@ -2608,7 +2608,9 @@ pub fn adjustCapacity(
errdefer self.destroyNode(new_node); errdefer self.destroyNode(new_node);
const new_page: *Page = &new_node.data; const new_page: *Page = &new_node.data;
assert(new_page.capacity.rows >= page.capacity.rows); assert(new_page.capacity.rows >= page.capacity.rows);
assert(new_page.capacity.cols >= page.capacity.cols);
new_page.size.rows = page.size.rows; new_page.size.rows = page.size.rows;
new_page.size.cols = page.size.cols;
try new_page.cloneFrom(page, 0, page.size.rows); try new_page.cloneFrom(page, 0, page.size.rows);
// Fix up all our tracked pins to point to the new page. // Fix up all our tracked pins to point to the new page.
@ -6257,6 +6259,39 @@ test "PageList adjustCapacity to increase hyperlinks" {
} }
} }
test "PageList adjustCapacity after col shrink" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 2, 0);
defer s.deinit();
// Shrink columns - this updates size.cols but not capacity.cols
try s.resize(.{ .cols = 5, .reflow = false });
try testing.expectEqual(5, s.cols);
{
const page = &s.pages.first.?.data;
// capacity.cols is still 10, but size.cols should be 5
try testing.expectEqual(5, page.size.cols);
try testing.expect(page.capacity.cols >= 10);
}
// Now adjust capacity (e.g., to increase styles)
// This should preserve the current size.cols, not revert to capacity.cols
_ = try s.adjustCapacity(
s.pages.first.?,
.{ .styles = std_capacity.styles * 2 },
);
{
const page = &s.pages.first.?.data;
// After adjustCapacity, size.cols should still be 5, not 10
try testing.expectEqual(5, page.size.cols);
try testing.expectEqual(5, s.cols);
}
}
test "PageList pageIterator single page" { test "PageList pageIterator single page" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;