Skip to content

Commit

Permalink
add home/end key support
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 11, 2024
1 parent 2aa00f7 commit e316b1b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 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,
HOME_KEY,
END_KEY,
PAGE_UP,
PAGE_DOWN,
}
Expand Down Expand Up @@ -80,12 +82,24 @@ function editorReadKey(): number {
if (seq[1] >= '0' && seq[1] <= '9') {
if (seq[2] == '~') {
switch (seq[1]) {
case '1':
return EditorKey.HOME_KEY;
break;
case '4':
return EditorKey.END_KEY;
break;
case '5':
return EditorKey.PAGE_UP;
break;
case '6':
return EditorKey.PAGE_DOWN;
break;
case '7':
return EditorKey.HOME_KEY;
break;
case '8':
return EditorKey.END_KEY;
break;
}
}
} else {
Expand All @@ -102,8 +116,22 @@ function editorReadKey(): number {
case 'D':
return EditorKey.ARROW_LEFT
break;
case 'H':
return EditorKey.HOME_KEY;
break;
case 'F':
return EditorKey.END_KEY;
}
}
} else if (seq[0] == 'O') {
switch (seq[1]) {
case 'H':
return EditorKey.HOME_KEY;
break;
case 'F':
return EditorKey.END_KEY;
break;
}
}

return 0x1b;
Expand Down Expand Up @@ -217,6 +245,14 @@ function editorProcessKeypress() {
exit('ciao, ciao');
break;

case EditorKey.HOME_KEY:
e.cursorX = 0;
break;

case EditorKey.END_KEY:
e.cursorX = e.screenCols - 1;
break;

case EditorKey.PAGE_UP:
case EditorKey.PAGE_DOWN:
let times = e.screenRows;
Expand Down

0 comments on commit e316b1b

Please sign in to comment.