Skip to content

Commit

Permalink
limit right scrolling and snap to end of line
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 12, 2024
1 parent 3f57a0c commit 422babf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,17 @@ function editorRefreshScreen() {
}

function editorMoveCursor(key: string | number) {
let row = (e.cursorY >= e.numRows) ? "" : e.row[e.cursorY];
switch (key) {
case EditorKey.ARROW_LEFT:
if (e.cursorX != 0) {
e.cursorX--;
}
break;
case EditorKey.ARROW_RIGHT:
e.cursorX++;
if (row != "" && e.cursorX < row.length) {
e.cursorX++;
}
break;
case EditorKey.ARROW_UP:
if (e.cursorY != 0) {
Expand All @@ -286,6 +289,12 @@ function editorMoveCursor(key: string | number) {
}
break;
}

row = (e.cursorY >= e.numRows) ? "" : e.row[e.cursorY];
const rowLen = row != "" ? row.length : 0;
if (e.cursorX > rowLen) {
e.cursorX = rowLen;
}
}

function editorProcessKeypress() {
Expand Down

0 comments on commit 422babf

Please sign in to comment.