From 9c20e2d463fe8c0f8a6f147e472f39e0777cf261 Mon Sep 17 00:00:00 2001 From: jmug Date: Tue, 27 Oct 2026 00:54:59 -0700 Subject: [PATCH] feat: Handle end and home keys. --- kilo.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/kilo.c b/kilo.c index 26c453b..af54aae 100644 --- a/kilo.c +++ b/kilo.c @@ -21,6 +21,8 @@ enum editorKey { ARROW_RIGHT, ARROW_UP, ARROW_DOWN, + HOME_KEY, + END_KEY, PAGE_UP, PAGE_DOWN }; @@ -101,8 +103,12 @@ int editorReadKey() { // NOTE: On MacOS and Ghostty specifically, fn+arrow[up/down] is // not sent as a page up/dow. Because it can mess up system keybindings. switch (seq[1]) { + case '1': return HOME_KEY; + case '4': return END_KEY; case '5': return PAGE_UP; case '6': return PAGE_DOWN; + case '7': return HOME_KEY; + case '8': return END_KEY; } } } else { @@ -112,8 +118,15 @@ int editorReadKey() { case 'B': return ARROW_DOWN; case 'C': return ARROW_RIGHT; case 'D': return ARROW_LEFT; + case 'H': return HOME_KEY; + case 'F': return END_KEY; } } + } else if (seq[0] == 'O') { + switch (seq[1]) { + case 'H': return HOME_KEY; + case 'F': return END_KEY; + } } return '\x1b'; @@ -289,6 +302,13 @@ void editorProcessKeypress() { exit(0); break; + case HOME_KEY: + E.cx = 0; + break; + case END_KEY: + E.cx = E.screencols - 1; + break; + case PAGE_UP: case PAGE_DOWN: { int times = E.screenrows; @@ -296,6 +316,7 @@ void editorProcessKeypress() { editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN); } } break; + case ARROW_UP: case ARROW_LEFT: case ARROW_DOWN: