fix: preserve active cursor position during reflow

This PR fixes an issue where reflowing could leave the active cursor
attached to a clipped trailing blank cell instead of following the
current write position.
This commit is contained in:
Riccardo Mazzarini
2026-05-06 14:52:36 +02:00
parent f9a9d33b3a
commit c44afa6250
2 changed files with 73 additions and 9 deletions

View File

@@ -1766,7 +1766,11 @@ pub inline fn resize(
.rows = opts.rows,
.cols = opts.cols,
.reflow = opts.reflow,
.cursor = .{ .x = self.cursor.x, .y = self.cursor.y },
.cursor = .{
.x = self.cursor.x,
.y = self.cursor.y,
.pin = self.cursor.page_pin,
},
});
// If we have no scrollback and we shrunk our rows, we must explicitly
@@ -7277,6 +7281,41 @@ test "Screen: resize less cols to eliminate wide char with row space" {
}
}
test "Screen: resize less cols reflows cursor after wrapped text" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try Screen.init(alloc, .{ .cols = 50, .rows = 7, .max_scrollback = 0 });
defer s.deinit();
for (0..30) |_| try s.testWriteString("a");
try testing.expectEqual(@as(usize, 0), s.cursor.y);
try testing.expectEqual(@as(usize, 30), s.cursor.x);
try s.resize(.{ .cols = 25, .rows = 7 });
try testing.expectEqual(@as(usize, 1), s.cursor.y);
try testing.expectEqual(@as(usize, 5), s.cursor.x);
}
test "Screen: resize less cols reflows cursor after empty cells" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try Screen.init(alloc, .{ .cols = 10, .rows = 3, .max_scrollback = 0 });
defer s.deinit();
try s.testWriteString("abc");
s.cursorRight(6);
try testing.expectEqual(@as(usize, 0), s.cursor.y);
try testing.expectEqual(@as(usize, 9), s.cursor.x);
try s.resize(.{ .cols = 5, .rows = 3 });
try testing.expectEqual(@as(usize, 1), s.cursor.y);
try testing.expectEqual(@as(usize, 4), s.cursor.x);
}
test "Screen: resize more cols with wide spacer head" {
const testing = std.testing;
const alloc = testing.allocator;