From 9524ba4df9c8dabf44c561cdc8e4c51f43f12f05 Mon Sep 17 00:00:00 2001 From: Rockingcool Date: Thu, 20 Apr 2023 23:54:48 -0500 Subject: [PATCH] Implemented rudimentary 'page down' key support, which moves the cursor to the first character of the next line --- editor.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/editor.c b/editor.c index 755e6bd..b1d4eeb 100644 --- a/editor.c +++ b/editor.c @@ -82,6 +82,26 @@ void buffer_left(Buffer* buffer) { } } + +void page_down_handler(Buffer* buffer) { + buffer_right(buffer); /* I must advance the cursor at least + once, so this hardcoded statement is fine. */ + + + while (*(buffer->start - 1) != '\n') { + buffer_right(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) + is, is actually the character _after_ the gap. Therefore, by + advancing the start to the newline character, the character + after the gap (i.e. the cursor) will automatically be moved to + the next line. */ + +} + void init_curses() { initscr(); noecho(); @@ -123,8 +143,6 @@ int main(int argc, char** argv) { } } - - init_curses(); int ch; @@ -184,8 +202,8 @@ int main(int argc, char** argv) { exception here), but that's a problem for another day. */ break; - case KEY_DOWN: - + case KEY_NPAGE: + page_down_handler(buffer); break; default: