From 866869a3921266055ff14ecca557f95ddb1c482b Mon Sep 17 00:00:00 2001 From: Kyle Loveless Date: Mon, 11 Nov 2024 13:59:02 -0600 Subject: [PATCH] bound cursor to screen --- main.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/main.ts b/main.ts index cc20166..50dc75d 100644 --- a/main.ts +++ b/main.ts @@ -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; } }