mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
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:
parent
9567694bab
commit
497c31d9fc
1 changed files with 5 additions and 13 deletions
18
commands.c
18
commands.c
|
|
@ -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 we’re 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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue