1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 05:12:40 +03:00

term: avoid panic in phys_row when row is out of range

Just clamp it to the current physical, non-scrollback portion
of the screen.

This avoids a panic but doesn't address the screen size mismatch
in the associated issue.

refs: https://github.com/wez/wezterm/issues/2133
This commit is contained in:
Wez Furlong 2022-07-26 09:34:49 -07:00
parent e7c7ea20f6
commit 858bc3ccce

View File

@ -447,12 +447,23 @@ impl Screen {
line.fill_range(cols, &Cell::blank_with_attrs(attr.clone()), seqno);
}
/// Ensure that row is within the range of the physical portion of
/// the screen; 0 .. physical_rows by clamping it to the nearest
/// boundary.
#[inline]
fn clamp_visible_row(&self, row: VisibleRowIndex) -> VisibleRowIndex {
(row.max(0) as usize).min(self.physical_rows) as VisibleRowIndex
}
/// Translate a VisibleRowIndex into a PhysRowIndex. The resultant index
/// will be invalidated by inserting or removing rows!
#[inline]
pub fn phys_row(&self, row: VisibleRowIndex) -> PhysRowIndex {
assert!(row >= 0, "phys_row called with negative row {}", row);
(self.lines.len() - self.physical_rows) + row as usize
let row = self.clamp_visible_row(row);
self.lines
.len()
.saturating_sub(self.physical_rows)
.saturating_add(row as PhysRowIndex)
}
/// Given a possibly negative row number, return the corresponding physical