about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-01-16 15:53:27 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-01-16 15:53:27 -0800
commitabc2ea467501c33c85d6923f96813a9832b3a6a0 (patch)
tree10affaeb685f2a8dcdb8c53166ac03b4de3615c2 /src
parent6499e933451a406df5665b746233c7df2f78cc11 (diff)
downloadteliva-abc2ea467501c33c85d6923f96813a9832b3a6a0.tar.gz
file access policy: support editing with >10 lines
Diffstat (limited to 'src')
-rw-r--r--src/kilo.c8
1 files 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);