aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-25 22:13:52 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-25 22:13:52 -0400
commit7501a610222e2eb1f99ed40c70dfc9cbb7cd9827 (patch)
tree545345086990d9c2b7d49f2f3fa6fd43aa6e7b3e
parent89d5aa2ca182416ba00280241b9959c2ea6911ff (diff)
downloadrunes-7501a610222e2eb1f99ed40c70dfc9cbb7cd9827.tar.gz
runes-7501a610222e2eb1f99ed40c70dfc9cbb7cd9827.zip
handle large counts for insert/delete characters
-rw-r--r--src/screen.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/screen.c b/src/screen.c
index 1917e16..bd9b461 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -209,12 +209,17 @@ void runes_screen_insert_characters(RunesTerm *t, int count)
RunesScreen *scr = &t->scr;
struct runes_row *row = &scr->rows[scr->cur.row];
- memmove(
- &row->cells[scr->cur.col + count], &row->cells[scr->cur.col],
- (scr->max.col - scr->cur.col - count) * sizeof(struct runes_cell));
- memset(
- &row->cells[scr->cur.col], 0,
- count * sizeof(struct runes_cell));
+ if (count >= scr->max.col - scr->cur.col) {
+ runes_screen_kill_line_forward(t);
+ }
+ else {
+ memmove(
+ &row->cells[scr->cur.col + count], &row->cells[scr->cur.col],
+ (scr->max.col - scr->cur.col - count) * sizeof(struct runes_cell));
+ memset(
+ &row->cells[scr->cur.col], 0,
+ count * sizeof(struct runes_cell));
+ }
}
void runes_screen_insert_lines(RunesTerm *t, int count)
@@ -229,12 +234,17 @@ void runes_screen_delete_characters(RunesTerm *t, int count)
RunesScreen *scr = &t->scr;
struct runes_row *row = &scr->rows[scr->cur.row];
- memmove(
- &row->cells[scr->cur.col], &row->cells[scr->cur.col + count],
- (scr->max.col - scr->cur.col - count) * sizeof(struct runes_cell));
- memset(
- &row->cells[scr->max.col - count], 0,
- count * sizeof(struct runes_cell));
+ if (count >= scr->max.col - scr->cur.col) {
+ runes_screen_kill_line_forward(t);
+ }
+ else {
+ memmove(
+ &row->cells[scr->cur.col], &row->cells[scr->cur.col + count],
+ (scr->max.col - scr->cur.col - count) * sizeof(struct runes_cell));
+ memset(
+ &row->cells[scr->max.col - count], 0,
+ count * sizeof(struct runes_cell));
+ }
}
void runes_screen_delete_lines(RunesTerm *t, int count)