diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index e4f82d557..b1588c9ca 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -707,13 +707,20 @@ impl TerminalState { pixel_width: usize, pixel_height: usize, ) { + // Compute the change in the height of the viewport; + // we'll use this to adjust the cursor position below. + let y_delta = (physical_rows as i64) - (self.screen().physical_rows as i64); self.screen.resize(physical_rows, physical_cols); self.scroll_region = 0..physical_rows as i64; self.pixel_height = pixel_height; self.pixel_width = pixel_width; self.tabs.resize(physical_cols); - // Ensure that the cursor is within the new bounds of the screen - self.set_cursor_pos(&Position::Relative(0), &Position::Relative(0)); + // Ensure that the cursor is within the new bounds of the screen. + // If we made the window smaller then we will have scrolled the + // viewport contents up by the delta. + // If we've made it larger then we do not want to adjust the + // cursor position + self.set_cursor_pos(&Position::Relative(0), &Position::Relative(y_delta.min(0))); } /// Clear the dirty flag for all dirty lines