From abc2ea467501c33c85d6923f96813a9832b3a6a0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 16 Jan 2022 15:53:27 -0800 Subject: [PATCH] file access policy: support editing with >10 lines --- src/kilo.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/kilo.c b/src/kilo.c index 5b6a9a7..5840dba 100644 --- a/src/kilo.c +++ b/src/kilo.c @@ -975,7 +975,7 @@ static void editorMoveCursor(int key) { } break; case KEY_DOWN: - if (filerow < E.numrows) { + if (filerow < E.numrows-1) { if (E.startrow + E.cy == E.endrow-1) { E.rowoff++; } else { @@ -1272,6 +1272,8 @@ void editNonCode(char* filename) { } } +#define MIN(x, y) ((x) < (y) ? (x) : (y)) + void editNonCode2(char* filename) { Quit = 0; Back_to_big_picture = 0; @@ -1287,7 +1289,7 @@ void editNonCode2(char* filename) { int y, x; getyx(stdscr, y, x); mvaddstr(0, 0, "function file_operation_permitted(filename, mode)"); - mvaddstr(E.startrow + E.numrows - E.rowoff, 0, "end"); + mvaddstr(MIN(E.startrow + E.numrows, E.endrow), 0, "end"); mvaddstr(y, x, ""); int c = getch(); editorProcessKeypress2(c); @@ -1359,7 +1361,7 @@ void resumeNonCodeEdit2() { int y, x; getyx(stdscr, y, x); mvaddstr(0, 0, "function file_operation_permitted(filename, mode)"); - mvaddstr(E.startrow + E.numrows - E.rowoff, 0, "end"); + mvaddstr(MIN(E.startrow + E.numrows, E.endrow), 0, "end"); mvaddstr(y, x, ""); int c = getch(); editorProcessKeypress2(c);