From 9669332134bee01d0f88e1610175b9fcaa68820e Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Fri, 6 Sep 2024 17:47:29 -0400 Subject: [PATCH] terminal: cursorResetWrap should not reset wrap_continuation --- src/terminal/Screen.zig | 58 +++++++++++---------------------------- src/terminal/Terminal.zig | 4 +-- 2 files changed, 18 insertions(+), 44 deletions(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 1df2de713..cb6c36017 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -1042,58 +1042,32 @@ pub fn cursorMarkDirty(self: *Screen) void { } /// Reset the cursor row's soft-wrap state and the cursor's pending wrap. -/// Also clears spacer heads from the cursor row and prior row as necessary. +/// Also handles clearing the spacer head on the cursor row and resetting +/// the wrap_continuation flag on the next row if necessary. pub fn cursorResetWrap(self: *Screen) void { // Reset the cursor's pending wrap state self.cursor.pending_wrap = false; const page_row = self.cursor.page_row; - if (!(page_row.wrap or page_row.wrap_continuation)) return; - - const cells = self.cursor.page_pin.cells(.all); - - // The previous row does not wrap and this row is not wrapped to - if (page_row.wrap_continuation) { - page_row.wrap_continuation = false; - - if (self.cursor.page_pin.up(1)) |prev_row| { - const p_rac = prev_row.rowAndCell(); - p_rac.row.wrap = false; - - // If the first cell in a row is wide the previous row - // may have a spacer head which needs to be cleared. - if (cells[0].wide == .wide) { - const p_cells = prev_row.cells(.all); - const p_cell = p_cells[prev_row.page.data.size.cols - 1]; - if (p_cell.wide == .spacer_head) { - self.clearCells( - &prev_row.page.data, - p_rac.row, - p_cells[prev_row.page.data.size.cols - 1 ..][0..1], - ); - } - } - } - } + if (!page_row.wrap) return; // This row does not wrap and the next row is not wrapped to - if (page_row.wrap) { - page_row.wrap = false; + page_row.wrap = false; - if (self.cursor.page_pin.down(1)) |next_row| { - next_row.rowAndCell().row.wrap_continuation = false; - } + if (self.cursor.page_pin.down(1)) |next_row| { + next_row.rowAndCell().row.wrap_continuation = false; + } - // If the last cell in the row is a spacer head we need to clear it. - const cell = cells[self.cursor.page_pin.page.data.size.cols - 1]; - if (cell.wide == .spacer_head) { - self.clearCells( - &self.cursor.page_pin.page.data, - page_row, - cells[self.cursor.page_pin.page.data.size.cols - 1 ..][0..1], - ); - } + // If the last cell in the row is a spacer head we need to clear it. + const cells = self.cursor.page_pin.cells(.all); + const cell = cells[self.cursor.page_pin.page.data.size.cols - 1]; + if (cell.wide == .spacer_head) { + self.clearCells( + &self.cursor.page_pin.page.data, + page_row, + cells[self.cursor.page_pin.page.data.size.cols - 1 ..][0..1], + ); } } diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index f51e54a76..b3e19b708 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -6083,7 +6083,7 @@ test "Terminal: eraseChars wide char wrap boundary conditions" { const unwrapped = try t.plainStringUnwrapped(alloc); defer testing.allocator.free(unwrapped); - try testing.expectEqualStrings(".......\n cde\nšŸ˜€......", unwrapped); + try testing.expectEqualStrings("....... cde\nšŸ˜€......", unwrapped); } } @@ -9049,7 +9049,7 @@ test "Terminal: deleteChars wide char wrap boundary conditions" { const unwrapped = try t.plainStringUnwrapped(alloc); defer testing.allocator.free(unwrapped); - try testing.expectEqualStrings(".......\n cde\nšŸ˜€......", unwrapped); + try testing.expectEqualStrings("....... cde\nšŸ˜€......", unwrapped); } }