26 lines
688 B
JavaScript
26 lines
688 B
JavaScript
export function moveUp(buffer, cursor) {
|
|
if (cursor.line > 0) cursor.line--;
|
|
cursor.col = Math.min(cursor.col, buffer[cursor.line].length);
|
|
}
|
|
|
|
export function moveDown(buffer, cursor) {
|
|
if (cursor.line < buffer.length - 1) cursor.line++;
|
|
cursor.col = Math.min(cursor.col, buffer[cursor.line].length);
|
|
}
|
|
|
|
export function moveLeft(buffer, cursor) {
|
|
if (cursor.col > 0) cursor.col--;
|
|
else if (cursor.line > 0) {
|
|
cursor.line--;
|
|
cursor.col = buffer[cursor.line].length;
|
|
}
|
|
}
|
|
|
|
export function moveRight(buffer, cursor) {
|
|
if (cursor.col < buffer[cursor.line].length) cursor.col++;
|
|
else if (cursor.line < buffer.length - 1) {
|
|
cursor.line++;
|
|
cursor.col = 0;
|
|
}
|
|
}
|