From a99759398841d86928c7ad4d8248f907765cbeb2 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Sat, 27 Jul 2019 08:31:24 +0100 Subject: add crop-to-visible function (C) --- screen.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'screen.c') diff --git a/screen.c b/screen.c index 0c5f2d8..965d440 100644 --- a/screen.c +++ b/screen.c @@ -197,6 +197,26 @@ void update_current(){ fflush(stdout); } +void erase_blank_lines(int y1, int y2){ + int j; + if (y1 > y2){ + y1 ^= y2; + y2 ^= y1; + y1 ^= y2; + } + + for (; y1 <= y2; y1++){ + j = screen[y1].lst; + while (j>=0 && isblank(screen[y1].s[j])) + j--; + if (j<0){ + screen[y1].lst = -1; + screen[y1].s[0] = '\0'; + } + } +} + + void erase_line(int i){ screen[i].lst = -1; screen[i].s[0] = '\0'; @@ -446,13 +466,16 @@ void find_nonblank_rect(int *x1, int *y1, int *x2, int *y2){ *y2 = i; if (i < *y1) *y1 = i; - if (screen[i].lst > *x2) - *x2 = screen[i].lst; j = 0; - while(j <= screen[i].lst && isblank(first=screen[i].s[j])) + while((j <= screen[i].lst) && isblank(first=screen[i].s[j])) j++; if (j < *x1) *x1 = j; + j = screen[i].lst; + while(isblank(screen[i].s[j])) + j--; + if (j > *x2) + *x2 = j; } } @@ -478,6 +501,7 @@ void crop_to_nonblank(){ fprintf(stderr, "crop rectangle: (%d, %d)-(%d, %d)\n", x1, y1, x2, y2); #endif crop_to_rect(x1, y1, x2, y2); + modified=1; redraw(); } -- cgit v1.2.3