aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/terminal/PageList.zig
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-06-04 16:32:43 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-06-04 16:32:43 +0300
commit648afa1fd5b4c2eb74b4292b4eceeeb6d93016c1 (patch)
tree368bce0f173319b98bce0e99f0c829fcd54520b3 /vendor/libghostty-vt/src/terminal/PageList.zig
parentf5f753c7286ff4cc30cfe3a9d48c053bfe2881c7 (diff)
fix: backport libghostty resize overflow fix
refs #465
Diffstat (limited to 'vendor/libghostty-vt/src/terminal/PageList.zig')
-rw-r--r--vendor/libghostty-vt/src/terminal/PageList.zig35
1 files changed, 33 insertions, 2 deletions
diff --git a/vendor/libghostty-vt/src/terminal/PageList.zig b/vendor/libghostty-vt/src/terminal/PageList.zig
index 8e5cd193..63155962 100644
--- a/vendor/libghostty-vt/src/terminal/PageList.zig
+++ b/vendor/libghostty-vt/src/terminal/PageList.zig
@@ -1059,7 +1059,7 @@ fn resizeCols(
break :cursor .{
.tracked_pin = c.pin orelse try self.trackPin(p),
.untrack = c.pin == null,
- .remaining_rows = self.rows - c.y - 1,
+ .remaining_rows = self.rows -| (c.y + 1),
.wrapped_rows = wrapped,
};
} else null;
@@ -1192,7 +1192,7 @@ fn resizeCols(
break :wrapped wrapped;
};
- const current = self.rows - active_pt.active.y - 1;
+ const current = self.rows -| (active_pt.active.y + 1);
var req_rows = c.remaining_rows;
req_rows -|= wrapped -| c.wrapped_rows;
@@ -10828,6 +10828,37 @@ test "PageList resize (no reflow) less rows and cols" {
}
}
+test "PageList resize less rows and cols cursor at bottom" {
+ const testing = std.testing;
+ const alloc = testing.allocator;
+
+ var s = try init(alloc, 80, 24, 0);
+ defer s.deinit();
+
+ const cursor_pin = try s.trackPin(s.pin(.{ .active = .{
+ .x = 0,
+ .y = s.rows - 1,
+ } }).?);
+ defer s.untrackPin(cursor_pin);
+
+ // Shrink both axes so the original cursor.y is strictly past the new row
+ // count, after resizeWithoutReflow has already reduced self.rows.
+ try s.resize(.{
+ .cols = 79,
+ .rows = 20,
+ .reflow = true,
+ .cursor = .{ .x = 0, .y = 23, .pin = cursor_pin },
+ });
+ try testing.expectEqual(@as(usize, 79), s.cols);
+ try testing.expectEqual(@as(usize, 20), s.rows);
+
+ // remaining_rows saturates to 0, so the cursor lands on the new bottom row.
+ try testing.expectEqual(point.Point{ .active = .{
+ .x = 0,
+ .y = s.rows - 1,
+ } }, s.pointFromPin(.active, cursor_pin.*).?);
+}
+
test "PageList resize (no reflow) more rows and less cols" {
const testing = std.testing;
const alloc = testing.allocator;