Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Dec 30, 2022
1 parent 14ad42d commit 8853150
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions kilo.c
Expand Up @@ -20,6 +20,8 @@ enum editorKey {
ARROW_RIGHT,
ARROW_UP,
ARROW_DOWN,
HOME_KEY,
END_KEY,
PAGE_UP,
PAGE_DOWN
};
Expand Down Expand Up @@ -83,10 +85,18 @@ int editorReadKey() {
if (read(STDIN_FILENO, &seq[2], 1) != 1) return '\x1b';
if (seq[2] == '~') {
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 {
Expand All @@ -99,8 +109,19 @@ int editorReadKey() {
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';
Expand Down Expand Up @@ -201,11 +222,19 @@ 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;
while (times--) editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN);
} break;

case ARROW_UP:
case ARROW_DOWN:
case ARROW_LEFT:
Expand Down

0 comments on commit 8853150

Please sign in to comment.