From df1c935a3a84e66e775d996c7d455d037c5fa0a3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 29 Feb 2024 22:22:46 -0800 Subject: [PATCH] terminal/new: pagelist resize rows and cols --- src/terminal/new/PageList.zig | 45 ++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/terminal/new/PageList.zig b/src/terminal/new/PageList.zig index 9a669e676..6644393f1 100644 --- a/src/terminal/new/PageList.zig +++ b/src/terminal/new/PageList.zig @@ -368,9 +368,7 @@ pub fn resize(self: *PageList, opts: Resize) !void { fn resizeWithoutReflow(self: *PageList, opts: Resize) !void { assert(!opts.reflow); - // If we're only changing the number of rows, it is a very fast operation. - if (opts.cols == null) { - const rows = opts.rows orelse return; + if (opts.rows) |rows| { switch (std.math.order(rows, self.rows)) { .eq => {}, @@ -1950,3 +1948,44 @@ test "PageList resize (no reflow) less cols then more cols" { try testing.expectEqual(@as(usize, 5), cells.len); } } + +test "PageList resize (no reflow) less rows and cols" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 10, 0); + defer s.deinit(); + + // Resize less + try s.resize(.{ .cols = 5, .rows = 7, .reflow = false }); + try testing.expectEqual(@as(usize, 5), s.cols); + try testing.expectEqual(@as(usize, 7), s.rows); + + var it = s.rowIterator(.{ .screen = .{} }, null); + while (it.next()) |offset| { + const rac = offset.rowAndCell(0); + const cells = offset.page.data.getCells(rac.row); + try testing.expectEqual(@as(usize, 5), cells.len); + } +} + +test "PageList resize (no reflow) more rows and less cols" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 10, 0); + defer s.deinit(); + + // Resize less + try s.resize(.{ .cols = 5, .rows = 20, .reflow = false }); + try testing.expectEqual(@as(usize, 5), s.cols); + try testing.expectEqual(@as(usize, 20), s.rows); + try testing.expectEqual(@as(usize, 20), s.totalRows()); + + var it = s.rowIterator(.{ .screen = .{} }, null); + while (it.next()) |offset| { + const rac = offset.rowAndCell(0); + const cells = offset.page.data.getCells(rac.row); + try testing.expectEqual(@as(usize, 5), cells.len); + } +}