From 6b59986fcaa8380a3076f7a7a9c7b81d7fa48e68 Mon Sep 17 00:00:00 2001 From: jmug Date: Mon, 26 Oct 2026 12:32:04 -0700 Subject: [PATCH] feat: Guard cursor movement. --- kilo.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kilo.c b/kilo.c index 2903953..8f5cba9 100644 --- a/kilo.c +++ b/kilo.c @@ -236,16 +236,24 @@ void editorRefreshScreen() { void editorMoveCursor(int key) { switch (key) { case ARROW_LEFT: - E.cx--; + if (E.cx != 0) { + E.cx--; + } break; case ARROW_RIGHT: - E.cx++; + if (E.cx != E.screencols - 1) { + E.cx++; + } break; case ARROW_UP: - E.cy--; + if (E.cy != 0) { + E.cy--; + } break; case ARROW_DOWN: - E.cy++; + if (E.cy != E.screenrows - 1) { + E.cy++; + } break; } }