mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
grid: reflow: make sure cursor is within the visible screen area
Even though we translate the cursor position from the old grid coordinates to the new, the cursor may _still_ end up outside the visible area. Make sure it doesn’t.
This commit is contained in:
parent
fc510d423b
commit
a1ab31eea5
2 changed files with 5 additions and 6 deletions
10
grid.c
10
grid.c
|
|
@ -331,16 +331,14 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
|
|||
cursor.row -= grid->offset;
|
||||
while (cursor.row < 0)
|
||||
cursor.row += grid->num_rows;
|
||||
|
||||
assert(cursor.row >= 0);
|
||||
assert(cursor.row < grid->num_rows);
|
||||
cursor.row = min(cursor.row, new_screen_rows - 1);
|
||||
assert(cursor.col >= 0 && cursor.col < new_cols);
|
||||
|
||||
saved_cursor.row -= grid->offset;
|
||||
while (saved_cursor.row < 0)
|
||||
saved_cursor.row += grid->num_rows;
|
||||
|
||||
assert(saved_cursor.row >= 0);
|
||||
assert(saved_cursor.row < grid->num_rows);
|
||||
saved_cursor.row = min(saved_cursor.row, new_screen_rows - 1);
|
||||
assert(saved_cursor.col >= 0 && saved_cursor.col < new_cols);
|
||||
|
||||
grid->cursor.point = cursor;
|
||||
grid->saved_cursor.point = saved_cursor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue