mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-15 22:05:24 -05:00
term: cursor-left: reverse-wrap when cursor is at the left margin
Assuming the private mode ‘reverse-wrap’ has been enabled.
This commit is contained in:
parent
060be30803
commit
03cacaba86
1 changed files with 38 additions and 3 deletions
41
terminal.c
41
terminal.c
|
|
@ -1728,9 +1728,44 @@ term_cursor_home(struct terminal *term)
|
|||
void
|
||||
term_cursor_left(struct terminal *term, int count)
|
||||
{
|
||||
int move_amount = min(term->grid->cursor.point.col, count);
|
||||
term->grid->cursor.point.col -= move_amount;
|
||||
assert(term->grid->cursor.point.col >= 0);
|
||||
assert(count >= 0);
|
||||
int new_col = term->grid->cursor.point.col - count;
|
||||
|
||||
/* Reverse wrap */
|
||||
if (unlikely(new_col < 0)) {
|
||||
if (unlikely(term->reverse_wrap)) {
|
||||
|
||||
/* Number of rows to reverse wrap through */
|
||||
int row_count = (abs(new_col) - 1) / term->cols + 1;
|
||||
|
||||
/* Row number cursor will end up on */
|
||||
int new_row_no = term->grid->cursor.point.row - row_count;
|
||||
|
||||
/* New column number */
|
||||
new_col = term->cols - ((abs(new_col) - 1) % term->cols + 1);
|
||||
assert(new_col >= 0 && new_col < term->cols);
|
||||
|
||||
/* Don't back up past the scroll region */
|
||||
/* TODO: should this be allowed? */
|
||||
if (new_row_no < term->scroll_region.start) {
|
||||
new_row_no = term->scroll_region.start;
|
||||
new_col = 0;
|
||||
}
|
||||
|
||||
struct row *new_row = grid_row(term->grid, new_row_no);
|
||||
term->grid->cursor.point.col = new_col;
|
||||
term->grid->cursor.point.row = new_row_no;
|
||||
term->grid->cursor.lcf = false;
|
||||
term->grid->cur_row = new_row;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Reverse wrap disabled - don't let cursor move past first column */
|
||||
new_col = 0;
|
||||
}
|
||||
|
||||
assert(new_col >= 0);
|
||||
term->grid->cursor.point.col = new_col;
|
||||
term->grid->cursor.lcf = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue