Skip to content

Commit

Permalink
implement page up/down, pretty sure the while(x--) loops have a bug yolo
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 11, 2024
1 parent 866869a commit 2aa00f7
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ enum EditorKey {
ARROW_RIGHT,
ARROW_UP,
ARROW_DOWN,
PAGE_UP,
PAGE_DOWN,
}

const e: EditorConfig = {};
Expand Down Expand Up @@ -75,19 +77,32 @@ function editorReadKey(): number {

const seq = decoder.decode(sequence);
if(seq[0] == '[') {
switch (seq[1]) {
case 'A':
return EditorKey.ARROW_UP;
break;
case 'B':
return EditorKey.ARROW_DOWN;
break;
case 'C':
return EditorKey.ARROW_RIGHT;
break;
case 'D':
return EditorKey.ARROW_LEFT
break;
if (seq[1] >= '0' && seq[1] <= '9') {
if (seq[2] == '~') {
switch (seq[1]) {
case '5':
return EditorKey.PAGE_UP;
break;
case '6':
return EditorKey.PAGE_DOWN;
break;
}
}
} else {
switch (seq[1]) {
case 'A':
return EditorKey.ARROW_UP;
break;
case 'B':
return EditorKey.ARROW_DOWN;
break;
case 'C':
return EditorKey.ARROW_RIGHT;
break;
case 'D':
return EditorKey.ARROW_LEFT
break;
}
}
}

Expand Down Expand Up @@ -199,7 +214,15 @@ function editorProcessKeypress() {

switch (char) {
case ctrlKey('q'):
exit('q->exit');
exit('ciao, ciao');
break;

case EditorKey.PAGE_UP:
case EditorKey.PAGE_DOWN:
let times = e.screenRows;
while (times--) {
editorMoveCursor(char == EditorKey.PAGE_UP ? EditorKey.ARROW_UP : EditorKey.ARROW_DOWN);
}
break;

case EditorKey.ARROW_UP:
Expand Down

0 comments on commit 2aa00f7

Please sign in to comment.