commands: scroll up: simplify viewport clamping logic

When scrolling the viewport up, we need to ensure we don’t go past the
scrollback wrap around.

This was previously done using “custom” logic that tried to calculate
many rows away from the scrollback start the current viewport is.

But this is *exactly* what grid_row_abs_to_sb() does, except it
doesn’t account for uninitialized scrollback.

So, copy the logic from grid_row_abs_to_sb(), but ensure scrollback
start points to valid scrollback data. The maximum number of rows
we’re allowed to scroll is now the same as the current viewport’s
sb-relative coordinate.

Maybe closes #1074
This commit is contained in:
Daniel Eklöf 2022-05-29 11:11:52 +02:00
parent 9567694bab
commit 497c31d9fc
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -32,20 +32,12 @@ cmd_scrollback_up(struct terminal *term, int rows)
scrollback_start &= grid_rows - 1;
}
/* Number of rows to scroll, without going past the scrollback start */
int max_rows = 0;
if (view + screen_rows >= grid_rows) {
/* View crosses scrollback wrap-around */
xassert(scrollback_start <= view);
max_rows = view - scrollback_start;
} else {
if (scrollback_start <= view)
max_rows = view - scrollback_start;
else
max_rows = view + (grid_rows - scrollback_start);
}
/* The view row number in scrollback relative coordinates. This is
* the maximum number of rows were allowed to scroll */
int view_sb_rel = view - scrollback_start + grid_rows;
view_sb_rel &= grid_rows - 1;
rows = min(rows, max_rows);
rows = min(rows, view_sb_rel);
if (rows == 0)
return;