terminal/search: reset pins while feeding

PageListSearch.feed changed only the node of its tracked progress pin. If the preceding history page had fewer rows or columns after a split, the retained bottom-right coordinates fell outside that page and the next PageList integrity check panicked.

Reset both coordinates to the new node's actual bottom-right cell whenever feed advances. The progress pin now remains valid across heterogeneous page sizes.
This commit is contained in:
Mitchell Hashimoto
2026-07-09 22:58:51 -07:00
parent d239f98056
commit 5d8eb78b73

View File

@@ -126,6 +126,9 @@ pub const PageListSearch = struct {
// Move our tracked pin to the new node.
self.pin.node = node;
self.pin.y = node.rows() - 1;
self.pin.x = node.cols() - 1;
self.pin.garbage = false;
if (rem == 0) break;
}
@@ -510,3 +513,31 @@ test "feed with pruned page" {
// Feed should still do nothing
try testing.expect(!try search.feed());
}
test "feed keeps its tracked pin within a shorter page" {
const alloc = testing.allocator;
var pages: PageList = try .init(alloc, 10, 2, null);
defer pages.deinit();
const first = pages.pages.first.?;
while (first.rows() < first.capacity().rows) _ = try pages.grow();
const second = (try pages.grow()).?;
while (second.rows() < second.capacity().rows) _ = try pages.grow();
try pages.split(.{ .node = first, .y = 1, .x = 0 });
const shorter = first.next.?;
try testing.expect(shorter.rows() < second.rows());
var search: PageListSearch = try .init(
alloc,
"x",
&pages,
second,
);
defer search.deinit();
try testing.expect(try search.feed());
try testing.expectEqual(shorter, search.pin.node);
try testing.expect(pages.pinIsValid(search.pin.*));
}