From 3775e25cdffdf83766a39887521084fa6f7c2844 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 27 Jun 2026 00:45:43 +0300 Subject: [PATCH] beer/grid: scroll to fit image when cursor is near bottom Signed-off-by: NotAShelf Change-Id: Ic95b18caca0c575b7d7452c87f9f1f956a6a6964 --- crates/beer/src/grid/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/beer/src/grid/mod.rs b/crates/beer/src/grid/mod.rs index e775c21..85dec08 100644 --- a/crates/beer/src/grid/mod.rs +++ b/crates/beer/src/grid/mod.rs @@ -782,7 +782,25 @@ impl Grid { rows: usize, keep_cursor: bool, ) { - let (x0, y0) = (self.cursor.x, self.cursor.y); + let x0 = self.cursor.x; + // Scroll the screen to make vertical room for the image. Only scroll + // when the full screen is the active scroll region; a DECSTBM region + // or the alternate screen keeps the image clipped as before. + let y0 = if self.top == 0 + && self.bottom == self.rows - 1 + && self.alt_saved.is_none() + { + let y0_initial = self.cursor.y; + let scroll_n = (y0_initial + rows) + .saturating_sub(self.rows) + .min(y0_initial); + if scroll_n > 0 { + self.scroll_up(scroll_n); + } + y0_initial - scroll_n + } else { + self.cursor.y + }; for dy in 0..rows { let cy = y0 + dy; if cy >= self.rows {