feat: Parse page up/down.
This commit is contained in:
@@ -20,7 +20,9 @@ enum editorKey {
|
||||
ARROW_LEFT = 1000,
|
||||
ARROW_RIGHT,
|
||||
ARROW_UP,
|
||||
ARROW_DOWN
|
||||
ARROW_DOWN,
|
||||
PAGE_UP,
|
||||
PAGE_DOWN
|
||||
};
|
||||
|
||||
/*** data ***/
|
||||
@@ -90,6 +92,21 @@ int editorReadKey() {
|
||||
return '\x1b';
|
||||
|
||||
if (seq[0] == '[') {
|
||||
if (seq[1] >= '0' && seq[1] <= '9') {
|
||||
// Parse a single digit escape seq arg:
|
||||
if (read(STDIN_FILENO, &seq[2], 1) != 1)
|
||||
return '\x1b';
|
||||
// `~` is the universal terminator for extended numeric key codes.
|
||||
if (seq[2] == '~') {
|
||||
// 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 '5': return PAGE_UP;
|
||||
case '6': return PAGE_DOWN;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Parse no arg seq otherwise:
|
||||
switch (seq[1]) {
|
||||
case 'A': return ARROW_UP;
|
||||
case 'B': return ARROW_DOWN;
|
||||
@@ -97,6 +114,7 @@ int editorReadKey() {
|
||||
case 'D': return ARROW_LEFT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '\x1b';
|
||||
}
|
||||
@@ -270,6 +288,14 @@ void editorProcessKeypress() {
|
||||
|
||||
exit(0);
|
||||
break;
|
||||
|
||||
case PAGE_UP:
|
||||
case PAGE_DOWN: {
|
||||
int times = E.screenrows;
|
||||
while (times--) {
|
||||
editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN);
|
||||
}
|
||||
} break;
|
||||
case ARROW_UP:
|
||||
case ARROW_LEFT:
|
||||
case ARROW_DOWN:
|
||||
|
||||
Reference in New Issue
Block a user