aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-16 11:14:58 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-16 11:14:58 +0000
commit81215e5a72bb9947505523294f58eed5ab5513f8 (patch)
tree317c2f71c316c8ab65f6d4c8ee434f1420778b7b
parentMerge branch 'tab-stop' (diff)
term: cursor_{up,down}: limit cursor movements based on origin mode
-rw-r--r--terminal.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/terminal.c b/terminal.c
index 8b7d6fa2..98551d3f 100644
--- a/terminal.c
+++ b/terminal.c
@@ -1060,14 +1060,20 @@ term_cursor_right(struct terminal *term, int count)
void
term_cursor_up(struct terminal *term, int count)
{
- int move_amount = min(term->cursor.row, count);
+ int top = term->origin == ORIGIN_ABSOLUTE ? 0 : term->scroll_region.start;
+ assert(term->cursor.row >= top);
+
+ int move_amount = min(term->cursor.row - top, count);
term_cursor_to(term, term->cursor.row - move_amount, term->cursor.col);
}
void
term_cursor_down(struct terminal *term, int count)
{
- int move_amount = min(term->rows - term->cursor.row - 1, count);
+ int bottom = term->origin == ORIGIN_ABSOLUTE ? term->rows : term->scroll_region.end;
+ assert(bottom >= term->cursor.row);
+
+ int move_amount = min(bottom - term->cursor.row - 1, count);
term_cursor_to(term, term->cursor.row + move_amount, term->cursor.col);
}