From e316b1b7113d7510e5fdd039e7ed8ae3ff92d38d Mon Sep 17 00:00:00 2001 From: Kyle Loveless Date: Mon, 11 Nov 2024 14:46:27 -0600 Subject: [PATCH] add home/end key support --- main.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/main.ts b/main.ts index afe8247..a9dab55 100644 --- a/main.ts +++ b/main.ts @@ -18,6 +18,8 @@ enum EditorKey { ARROW_RIGHT, ARROW_UP, ARROW_DOWN, + HOME_KEY, + END_KEY, PAGE_UP, PAGE_DOWN, } @@ -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 { @@ -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; @@ -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;