mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
term: simplify horizontal cursor movement
Since horizontal cursor movement is clamped to the current line, we can calculate the new linear cursor without any expensive multiplications and/or divisions.
This commit is contained in:
parent
e17d297dca
commit
dd4647e9ff
1 changed files with 6 additions and 2 deletions
|
|
@ -175,14 +175,18 @@ void
|
|||
term_cursor_left(struct terminal *term, int count)
|
||||
{
|
||||
int move_amount = min(term->cursor.col, count);
|
||||
term_cursor_to(term, term->cursor.row, term->cursor.col - move_amount);
|
||||
term->cursor.linear -= move_amount;
|
||||
term->cursor.col -= move_amount;
|
||||
term->print_needs_wrap = false;
|
||||
}
|
||||
|
||||
void
|
||||
term_cursor_right(struct terminal *term, int count)
|
||||
{
|
||||
int move_amount = min(term->cols - term->cursor.col - 1, count);
|
||||
term_cursor_to(term, term->cursor.row, term->cursor.col + move_amount);
|
||||
term->cursor.linear += move_amount;
|
||||
term->cursor.col += move_amount;
|
||||
term->print_needs_wrap = false;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue