PAGE UP and DOWN keys

This commit is contained in:
Saumya Bhatnagar 2018-05-28 12:37:42 +05:30
parent 7cdfcb3c4a
commit ec94419580
2 changed files with 28 additions and 6 deletions

BIN
editor

Binary file not shown.

View File

@ -18,7 +18,9 @@ enum editorKey {
ARROW_LEFT = 1000,
ARROW_RIGHT,
ARROW_UP,
ARROW_DOWN
ARROW_DOWN,
PAGE_UP,
PAGE_DOWN
};
/*** data ***/
@ -105,11 +107,23 @@ int editorReadKey() {
}
if (seq[0] == '[') {
switch(seq[1]) {
case 'A': return ARROW_UP;
case 'B': return ARROW_DOWN;
case 'C': return ARROW_RIGHT;
case 'D': return ARROW_LEFT;
if (seq[1] >= '0' && seq[1] <= '9') {
while (read(STDIN_FILENO, &seq[2], 1) != 1) {
return '\x1b';
}
if (seq[2] == '~') {
switch (seq[1]) {
case '5': return PAGE_UP;
case '6': return PAGE_DOWN;
}
}
} else {
switch(seq[1]) {
case 'A': return ARROW_UP;
case 'B': return ARROW_DOWN;
case 'C': return ARROW_RIGHT;
case 'D': return ARROW_LEFT;
}
}
}
@ -242,6 +256,14 @@ void editorProcessKey() {
case ARROW_UP:
editorMoveCursor(c);
break;
case PAGE_UP:
case PAGE_DOWN:
{
int ii = E.screenrows;
while (ii--) {
editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN);
}
}
}
}