refine vertical size adjustments when resizing the terminal
This commit is contained in:
1 parent
d91e384a7e
commit
2e581252c1
3 files changed
+19
-13
No files matched your search
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
+16
-12
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user