diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-05-29 09:11:52 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-06-13 09:53:37 +0000 |
| commit | 497c31d9fc0babf02d2bfdfa2f2633ae80cb24f7 (patch) | |
| tree | 7aff7d7560ff3c3fdb8065d9da570c5933dea2c5 | |
| parent | grid: reflow: don’t trim trailing empty cells from logical lines (diff) | |
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
| -rw-r--r-- | commands.c | 18 |
1 files changed, 5 insertions, 13 deletions
@@ -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; |
