diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-09-09 16:40:06 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-09-10 05:37:08 +0000 |
| commit | a1ab31eea563dc4bee81bddd8d99a861712f6230 (patch) | |
| tree | deb502a3076811850a6865eb980bb78aebab45c1 | |
| parent | Merge branch 'osc52-clear-selection-on-invalid-payload' into master (diff) | |
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.
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | grid.c | 10 |
2 files changed, 5 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e1853345..c876632d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,6 +114,7 @@ **not** include `Alt`. * Clipboard (or primary selection) is now cleared when receiving an OSC-52 command with an invalid base64 encoded payload. +* Cursor position being set outside the grid when reflowing text. ### Security @@ -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; |
