mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-15 22:05:24 -05:00
search: regression: crash when moving viewport
5c4ddebc3c refactored
search_update_selection(), specifically, the logic that moves the
viewport.
It did so by converting the absolute row number (of the match) to
scrollback relative coordinates. This way we could ensure the viewport
wasn’t moved “too much” (e.g. beyond the scrollback start).
However, grid_row_abs_to_sb() and grid_row_sb_to_abs() doesn’t take a
partially filled scrollback into account. This means the row (numbers)
it returns may refer to *uninitialized* rows.
Since:
* The match row itself is valid (we *know* it has text on it)
* We *subtract* from it, when setting the new viewport (to center the
match on the screen).
it’s only the *upper* part of the new viewport that may be
uninitialized. I.e. we may have adjusted it too much.
So, what we need to do is move the viewport forward until its *first*
row is initialized. Then we know the rest will be too.
This commit is contained in:
parent
93dcb7dc9c
commit
c82c6116ed
1 changed files with 7 additions and 0 deletions
7
search.c
7
search.c
|
|
@ -209,6 +209,13 @@ search_update_selection(struct terminal *term, const struct range *match)
|
|||
const int old_view = grid->view;
|
||||
int new_view = grid_row_sb_to_abs(grid, term->rows, rebased_new_view);
|
||||
|
||||
/* Scrollback may not be completely filled yet */
|
||||
{
|
||||
const int mask = grid->num_rows - 1;
|
||||
while (grid->rows[new_view] == NULL)
|
||||
new_view = (new_view + 1) & mask;
|
||||
}
|
||||
|
||||
#if defined(_DEBUG)
|
||||
/* Verify all to-be-visible rows have been allocated */
|
||||
for (int r = 0; r < term->rows; r++)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue