feat: Handle end and home keys.

This commit is contained in:
jmug
2026-10-27 00:54:59 -07:00
parent b85d656a74
commit 9c20e2d463
+21
View File
@@ -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: