From bb4bfa5c8af451356445dff2af7064ae914d51cf Mon Sep 17 00:00:00 2001 From: Kyle Loveless Date: Thu, 14 Nov 2024 15:47:37 -0600 Subject: [PATCH] work on line wrapping on delete --- main.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/main.ts b/main.ts index f30e0a1..3b1962c 100644 --- a/main.ts +++ b/main.ts @@ -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; @@ -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; @@ -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(); } }