terminal: PageList adjustCapacity should return new node and fix pins

This commit is contained in:
Mitchell Hashimoto
2024-03-11 19:08:55 -07:00
parent 7ff5577d05
commit 98b16930c3

View File

@ -1539,7 +1539,7 @@ pub fn adjustCapacity(
self: *PageList, self: *PageList,
page: *List.Node, page: *List.Node,
adjustment: AdjustCapacity, adjustment: AdjustCapacity,
) !void { ) !*List.Node {
// We always use our base capacity which is our standard // We always use our base capacity which is our standard
// adjusted for our column size. // adjusted for our column size.
var cap = try std_capacity.adjust(.{ .cols = self.cols }); var cap = try std_capacity.adjust(.{ .cols = self.cols });
@ -1557,10 +1557,20 @@ pub fn adjustCapacity(
new_page.data.size.rows = page.data.size.rows; new_page.data.size.rows = page.data.size.rows;
try new_page.data.cloneFrom(&page.data, 0, page.data.size.rows); try new_page.data.cloneFrom(&page.data, 0, page.data.size.rows);
// Fix up all our tracked pins to point to the new page.
var it = self.tracked_pins.keyIterator();
while (it.next()) |p_ptr| {
const p = p_ptr.*;
if (p.page != page) continue;
p.page = new_page;
}
// Insert this page and destroy the old page // Insert this page and destroy the old page
self.pages.insertBefore(page, new_page); self.pages.insertBefore(page, new_page);
self.pages.remove(page); self.pages.remove(page);
self.destroyPage(page); self.destroyPage(page);
return new_page;
} }
/// Create a new page node. This does not add it to the list and this /// Create a new page node. This does not add it to the list and this
@ -3105,7 +3115,7 @@ test "PageList adjustCapacity to increase styles" {
} }
// Increase our styles // Increase our styles
try s.adjustCapacity( _ = try s.adjustCapacity(
s.pages.first.?, s.pages.first.?,
.{ .styles = std_capacity.styles * 2 }, .{ .styles = std_capacity.styles * 2 },
); );