From 4a3376d91680d5a0d060d2ef3e108a082511e83a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 27 Nov 2022 21:06:11 -0800 Subject: [PATCH] fix crash with cursor going off screen on resize --- src/terminal/Screen.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 4b9161077..6b3bf3177 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -1716,7 +1716,8 @@ pub fn resizeWithoutReflow(self: *Screen, rows: usize, cols: usize) !void { // The cursor is normally in active coordinates, but by converting to // screen we can accomodate keeping it on the same place if we retain // the same scrollback. - const old_cursor_y_screen = RowIndexTag.active.index(old.cursor.y).toScreen(&old).screen; + const old_y = @max(old.cursor.y, old.rows - 1); + const old_cursor_y_screen = RowIndexTag.active.index(old_y).toScreen(&old).screen; self.cursor.x = @min(old.cursor.x, self.cols - 1); self.cursor.y = if (old_cursor_y_screen <= RowIndexTag.screen.maxLen(self)) old_cursor_y_screen -| self.history