From 2e581252c19fd3c0753bf1986c5ca5245d0d3600 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 11 Jan 2020 09:39:51 -0800 Subject: [PATCH] refine vertical size adjustments when resizing the terminal --- src/frontend/gui/termwindow.rs | 2 +- src/mux/renderable.rs | 2 ++ term/src/screen.rs | 28 ++++++++++++++++------------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index 165dac523..2287b1a64 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -1071,7 +1071,7 @@ impl TermWindow { let (first_row, lines) = renderer.get_lines(sel.rows()); for (idx, line) in lines.iter().enumerate() { let cols = sel.cols_for_row(first_row + idx as StableRowIndex); - let last_col_idx = cols.end.min(line.cells().len()) - 1; + let last_col_idx = cols.end.min(line.cells().len()).saturating_sub(1); if !s.is_empty() && !last_was_wrapped { s.push('\n'); } diff --git a/src/mux/renderable.rs b/src/mux/renderable.rs index 14fc472ea..a0e09ba11 100644 --- a/src/mux/renderable.rs +++ b/src/mux/renderable.rs @@ -28,6 +28,8 @@ pub struct RenderableDimensions { /// for the `get_lines` call when the scroll position is at the /// bottom of the screen. pub physical_top: StableRowIndex, + /// The top of the scrollback (the earliest row we remember) + /// expressed as a stable index. pub scrollback_top: StableRowIndex, } diff --git a/term/src/screen.rs b/term/src/screen.rs index 4884dc7e5..b0b6ad8a9 100644 --- a/term/src/screen.rs +++ b/term/src/screen.rs @@ -122,17 +122,11 @@ impl Screen { { self.lines.pop_back(); } - - // If we resized wider and the rewrap resulted in fewer - // lines than the viewport size, pad us back out to the - // viewport size - while self.lines.len() < physical_rows { - self.lines.push_back(Line::with_width(physical_cols)); - } } /// Resize the physical, viewable portion of the screen pub fn resize(&mut self, physical_rows: usize, physical_cols: usize) { + log::debug!("resize screen to {}x{}", physical_cols, physical_rows); let physical_rows = physical_rows.max(1); let physical_cols = physical_cols.max(1); @@ -150,14 +144,24 @@ impl Screen { self.lines.reserve(capacity - current_capacity); } - if physical_rows > self.physical_rows { - // Enlarging the viewable portion? Add more lines at the bottom - for _ in self.physical_rows..physical_rows { - self.lines.push_back(Line::with_width(physical_cols)); - } + // If we resized wider and the rewrap resulted in fewer + // lines than the viewport size, pad us back out to the + // viewport size + while self.lines.len() < physical_rows { + self.lines.push_back(Line::with_width(physical_cols)); } + // If we made the window bigger, we need to increase the total + // number of lines in order for the viewport position to hold + // steady: without this we'll drift backwards and operations + // such as erase to end of display will effectively destroy + // scrollback + for _ in self.physical_rows..physical_rows { + self.lines.push_back(Line::with_width(physical_cols)); + } + self.physical_rows = physical_rows; self.physical_cols = physical_cols; + log::debug!("there are now {} lines in this screen", self.lines.len()); } /// Get mutable reference to a line, relative to start of scrollback.