From 05fe2a83b19d7a26e7207e7abe7b2a5d7321d469 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 1 Mar 2023 21:30:31 -0800 Subject: [PATCH] terminal: erase display below should unwrap soft wrapped state --- src/terminal/Screen.zig | 15 +++++++-------- src/terminal/Terminal.zig | 27 +++++++++++++++++---------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 72090bf8c..3438cc745 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -1876,22 +1876,21 @@ pub fn resize(self: *Screen, rows: usize, cols: usize) !void { while (iter.next()) |old_row| { // If we're past the end, scroll if (y >= self.rows) { - y -= 1; try self.scroll(.{ .delta = 1 }); + y -= 1; } - // Get this row - var new_row = self.getRow(.{ .active = y }); - try new_row.copyRow(old_row); - // We need to check if our cursor was on this line. If so, // we set the new cursor. if (cursor_pos.y == iter.value - 1) { assert(new_cursor == null); // should only happen once - new_cursor = .{ .y = self.rowsWritten() - 1, .x = cursor_pos.x }; + new_cursor = .{ .y = self.history + y, .x = cursor_pos.x }; } - // If no reflow, just keep going. + // At this point, we're always at x == 0 so we can just copy + // the row (we know old.cols < self.cols). + var new_row = self.getRow(.{ .active = y }); + try new_row.copyRow(old_row); if (!old_row.header().flags.wrap) { // If we have no reflow, we attempt to extend any stylized // cells at the end of the line if there is one. @@ -1955,7 +1954,7 @@ pub fn resize(self: *Screen, rows: usize, cols: usize) !void { cursor_pos.x < copy_len and new_cursor == null) { - new_cursor = .{ .y = self.rowsWritten() - 1, .x = x + cursor_pos.x }; + new_cursor = .{ .y = self.history + y, .x = x + cursor_pos.x }; } // We copied the full amount left in this wrapped row. diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index fb0189d03..b67ab58b7 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -912,19 +912,26 @@ pub fn eraseDisplay( .below => { // All lines to the right (including the cursor) - var x: usize = self.screen.cursor.x; - while (x < self.cols) : (x += 1) { - const cell = self.screen.getCellPtr(.active, self.screen.cursor.y, x); - cell.* = self.screen.cursor.pen; - cell.char = 0; + { + const row = self.screen.getRow(.{ .active = self.screen.cursor.y }); + row.setWrapped(false); + row.setDirty(true); + for (self.screen.cursor.x..self.cols) |x| { + if (row.header().flags.grapheme) row.clearGraphemes(x); + const cell = row.getCellPtr(x); + cell.* = self.screen.cursor.pen; + cell.char = 0; + } } // All lines below - var y: usize = self.screen.cursor.y + 1; - while (y < self.rows) : (y += 1) { - x = 0; - while (x < self.cols) : (x += 1) { - const cell = self.screen.getCellPtr(.active, y, x); + for ((self.screen.cursor.y + 1)..self.rows) |y| { + const row = self.screen.getRow(.{ .active = y }); + row.setWrapped(false); + row.setDirty(true); + for (0..self.cols) |x| { + if (row.header().flags.grapheme) row.clearGraphemes(x); + const cell = row.getCellPtr(x); cell.* = self.screen.cursor.pen; cell.char = 0; }