diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 694698bc1..1aff79a0c 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -6513,6 +6513,12 @@ test "Screen: resize more cols perfect split" { const str = "1ABCD2EFGH3IJKL"; try s.testWriteString(str); try s.resize(3, 10); + + { + const contents = try s.testString(alloc, .screen); + defer alloc.free(contents); + try testing.expectEqualStrings("1ABCD2EFGH\n3IJKL", contents); + } } // X @@ -6669,6 +6675,7 @@ test "Screen: resize more cols grapheme map" { } } +// X test "Screen: resize more cols with reflow that fits full width" { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/terminal/new/PageList.zig b/src/terminal/new/PageList.zig index 6c6b89f0f..5f0c6e011 100644 --- a/src/terminal/new/PageList.zig +++ b/src/terminal/new/PageList.zig @@ -564,13 +564,14 @@ fn reflowPage( } } - src_cursor.cursorAbsolute(src_cursor.x, @intCast(src_y)); - + src_cursor.cursorAbsolute(0, @intCast(src_y)); for (src_cursor.x..src_cursor.page.size.cols) |src_x| { assert(src_cursor.x == src_x); if (dst_cursor.pending_wrap) { - @panic("TODO"); + dst_cursor.page_row.wrap = true; + dst_cursor.cursorScroll(); + dst_cursor.page_row.wrap_continuation = true; } switch (src_cursor.page_cell.content_tag) { diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index 3b8c35258..40ba84b2f 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -2224,6 +2224,12 @@ test "Screen: resize more cols perfect split" { const str = "1ABCD2EFGH3IJKL"; try s.testWriteString(str); try s.resize(10, 3); + + { + const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("1ABCD2EFGH\n3IJKL", contents); + } } // https://github.com/mitchellh/ghostty/issues/1159 @@ -2258,3 +2264,44 @@ test "Screen: resize (no reflow) more cols with scrollback scrolled up" { try testing.expectEqual(@as(size.CellCountInt, 1), s.cursor.x); try testing.expectEqual(@as(size.CellCountInt, 2), s.cursor.y); } + +test "Screen: resize more cols with reflow that fits full width" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 5, 3, 0); + defer s.deinit(); + const str = "1ABCD2EFGH\n3IJKL"; + try s.testWriteString(str); + + // Verify we soft wrapped + { + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + const expected = "1ABCD\n2EFGH\n3IJKL"; + try testing.expectEqualStrings(expected, contents); + } + + // Let's put our cursor on row 2, where the soft wrap is + s.cursorAbsolute(0, 1); + { + const list_cell = s.pages.getCell(.{ .active = .{ + .x = s.cursor.x, + .y = s.cursor.y, + } }).?; + try testing.expectEqual(@as(u21, '2'), list_cell.cell.content.codepoint); + } + + // Resize and verify we undid the soft wrap because we have space now + try s.resize(10, 3); + { + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings(str, contents); + } + + // Our cursor should've moved + // TODO + // try testing.expectEqual(@as(usize, 5), s.cursor.x); + // try testing.expectEqual(@as(usize, 0), s.cursor.y); +}