From 5554e0e927d0cdeb6c152f15e571903ad3c6fc09 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 16 Apr 2021 17:58:19 +0900 Subject: [PATCH] edit.js: hit return to add a new line in the middle of the text --- assets/disk0/tvdos/bin/edit.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/assets/disk0/tvdos/bin/edit.js b/assets/disk0/tvdos/bin/edit.js index b9d3f80..b12da19 100644 --- a/assets/disk0/tvdos/bin/edit.js +++ b/assets/disk0/tvdos/bin/edit.js @@ -243,7 +243,10 @@ function appendText(code) { } function appendLine() { - textbuffer.push(""); + //textbuffer.push(""); + let s1 = textbuffer[cursorRow].substring(0, cursorCol); + let s2 = textbuffer[cursorRow].substring(cursorCol); + textbuffer.splice(cursorRow, 1, s1, s2); // reset horizontal scroll before going to the next line scrollHor = 0; @@ -256,8 +259,9 @@ function appendLine() { if (cursorRow >= windowHeight - scrollPeek) { scroll += 1; drawLineNumbers(); - drawTextbuffer(); } + + drawTextbuffer(); } function nextCol() { @@ -332,10 +336,13 @@ while (!exit) { nextCol(); drawLnCol(); gotoText(); } else if (key == con.KEY_HOME) { - cursorCol = 0; scrollHor = 0; drawTextLine(cursorRow - scroll); drawLnCol(); gotoText(); + cursorCol = 0; scrollHor = 0; + drawTextLine(cursorRow - scroll); drawLnCol(); gotoText(); } else if (key == con.KEY_END) { - cursorCol = textbuffer[cursorRow].length; scrollHor = textbuffer[cursorRow].length - paintWidth + 2; drawTextLine(cursorRow - scroll); drawLnCol(); gotoText(); + cursorCol = textbuffer[cursorRow].length; + scrollHor = textbuffer[cursorRow].length - paintWidth + 2; + drawTextLine(cursorRow - scroll); drawLnCol(); gotoText(); } else if (key >= 32 && key < 128) { // printables (excludes \n) appendText(key);