From d91e384a7ec998b5793131bbdd2d8ffcbb97c5a1 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 11 Jan 2020 08:44:28 -0800 Subject: [PATCH] improve cursor position adjustment on resize Avoids accidentally moving the y position of the cursor; previously we would keep it pinned to the physical viewport relative coordinate, but we didn't account for the implicit scroll that happens when making the window smaller, which meant that the shell would re-render its prompt with some artifacts during a resize. --- term/src/terminalstate.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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