terminal: handle minimum prompt scroll delta

Prompt scrolling negated negative deltas to count the requested jumps.
minInt(isize) has no positive signed representation, so a caller could
trigger a runtime safety panic before the search for an earlier prompt
started.

Use @abs to produce the full unsigned magnitude. An extreme negative
request now follows the normal prompt traversal and clamps at the oldest
available prompt.
This commit is contained in:
Mitchell Hashimoto
2026-07-09 20:20:46 -07:00
parent c753fe4a4f
commit afbf5ba156

View File

@@ -3009,7 +3009,7 @@ pub fn scroll(self: *PageList, behavior: Scroll) void {
fn scrollPrompt(self: *PageList, delta: isize) void {
// If we aren't jumping any prompts then we don't need to do anything.
if (delta == 0) return;
const delta_start: usize = @intCast(if (delta > 0) delta else -delta);
const delta_start: usize = @abs(delta);
var delta_rem: usize = delta_start;
// We start at the row before or after our viewport depending on the
@@ -8833,6 +8833,16 @@ test "PageList: jump zero prompts" {
}, s.scrollbar());
}
test "PageList: jump minimum prompt delta" {
const testing = std.testing;
var s = try init(testing.allocator, 10, 3, null);
defer s.deinit();
s.scroll(.{ .delta_prompt = std.math.minInt(isize) });
try testing.expectEqual(Viewport.active, s.viewport);
}
test "Screen: jump back one prompt" {
const testing = std.testing;
const alloc = testing.allocator;