Skip to content

Commit

Permalink
work on line wrapping on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 14, 2024
1 parent efddb2c commit bb4bfa5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,19 @@ function editorAppendRow(msg: string) {
e.dirty++;
}

function editorFreeRow(row: number) {
e.row[row] = "";
e.render[row] = "";
}

function editorDelRow(at: number) {
if (at < 0 || at >= e.numRows) return;

editorFreeRow(at);
e.row.splice(at, 1);
e.dirty++;
}

function editorRowInsertChar(row: number, at: number, char: string) {
if (at < 0 || at > e.row[row].length) at = e.row[row].length;

Expand All @@ -220,6 +233,12 @@ function editorRowInsertChar(row: number, at: number, char: string) {
e.dirty++;
}

function editorRowAppendString(row: number, msg: string) {
e.row[row] += msg;
editorUpdateRow(e.cursorY);
e.dirty++;
}

function editorRowDelChar(row: number, at: number) {
if (at < 0 || at >= e.row[row].length) return;

Expand All @@ -238,10 +257,18 @@ function editorInsertChar(char: string) {

function editorDelChar() {
if (e.cursorY == e.numRows) return;
if (e.cursorX == 0 && e.cursorY == 0) return;

if (e.cursorX > 0) {
editorRowDelChar(e.cursorY, e.cursorX - 1);
e.cursorX--;
} else {
e.cursorX = e.row[e.cursorY - 1].length;
editorRowAppendString(e.cursorY - 1, e.row[e.cursorY]);
editorDelRow(e.cursorY);
e.cursorY--;
console.log(`\n\n\n\nhere: ${e.row}`)
Deno.exit();
}
}

Expand Down

0 comments on commit bb4bfa5

Please sign in to comment.