terminal: add assertion for trackPin as commented

This commit is contained in:
Mitchell Hashimoto
2024-03-20 16:18:29 -07:00
parent 91602a4ce7
commit 9d826d8837

View File

@ -1986,7 +1986,7 @@ pub fn pin(self: *const PageList, pt: point.Point) ?Pin {
/// pin points to is removed completely, the tracked pin will be updated
/// to the top-left of the screen.
pub fn trackPin(self: *PageList, p: Pin) !*Pin {
// TODO: assert pin is valid
if (comptime std.debug.runtime_safety) assert(self.pinIsValid(p));
// Create our tracked pin
const tracked = try self.pool.pins.create();
@ -2012,6 +2012,20 @@ pub fn countTrackedPins(self: *const PageList) usize {
return self.tracked_pins.count();
}
/// Checks if a pin is valid for this pagelist. This is a very slow and
/// expensive operation since we traverse the entire linked list in the
/// worst case. Only for runtime safety/debug.
fn pinIsValid(self: *const PageList, p: Pin) bool {
var it = self.pages.first;
while (it) |page| : (it = page.next) {
if (page != p.page) continue;
return p.y < page.data.size.rows and
p.x < page.data.size.cols;
}
return false;
}
/// Returns the viewport for the given pin, prefering to pin to
/// "active" if the pin is within the active area.
fn pinIsActive(self: *const PageList, p: Pin) bool {