From 563271d1b26738dd9515c3ba9e6eb6b9bac6c223 Mon Sep 17 00:00:00 2001 From: Rockingcool Date: Fri, 21 Apr 2023 08:11:55 -0500 Subject: [PATCH] Coninued working on page overflow --- editor.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/editor.c b/editor.c index b1d4eeb..67232b3 100644 --- a/editor.c +++ b/editor.c @@ -6,6 +6,8 @@ #include #include +int index_to_start = 0; + typedef struct Buffer_struct Buffer; struct Buffer_struct { char* text; @@ -83,6 +85,13 @@ void buffer_left(Buffer* buffer) { } + +void scroll_page_down_handler(Buffer* buffer) { + while (*(buffer->start + index_to_start) != '\n') { + index_to_start++; + } +} + void page_down_handler(Buffer* buffer) { buffer_right(buffer); /* I must advance the cursor at least once, so this hardcoded statement is fine. */ @@ -92,6 +101,10 @@ void page_down_handler(Buffer* buffer) { buffer_right(buffer); } + if ((getcury(stdscr) + 1) == getmaxy(stdscr)) { + scroll_page_down_handler(buffer); + } + /* You would think that I need to call 'buffer_right' once more, to advance the cursor onto the next line. In fact, if you think about it, the place where the cursor (the rectangle) @@ -116,7 +129,6 @@ void sigint_handler(int dummy) { } int main(int argc, char** argv) { - int index_to_start = 0; signal(SIGINT,sigint_handler); Buffer* buffer = new_buffer(10);