Skip to content

Commit

Permalink
bound cursor to screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 11, 2024
1 parent 976bcf0 commit 866869a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,26 @@ function editorRefreshScreen() {
}

function editorMoveCursor(key: string | number) {
console.log(key);
switch (key) {
case EditorKey.ARROW_LEFT:
e.cursorX--;
if (e.cursorX != 0) {
e.cursorX--;
}
break;
case EditorKey.ARROW_RIGHT:
e.cursorX++;
break
if (e.cursorX != e.screenCols - 1) {
e.cursorX++;
}
break;
case EditorKey.ARROW_UP:
e.cursorY--;
if (e.cursorY != 0) {
e.cursorY--;
}
break;
case EditorKey.ARROW_DOWN:
e.cursorY++;
if (e.cursorY != e.screenRows - 1) {
e.cursorY++;
}
break;
}
}
Expand Down

0 comments on commit 866869a

Please sign in to comment.