mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-14 15:06:05 +09:00
edit.js: adding/deleting a text or a line works again
This commit is contained in:
@@ -185,8 +185,10 @@ function drawTextLineAbsolute(rowNumber, paintOffsetX) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawTextbuffer() {
|
function drawTextbuffer(from, toExclusive) {
|
||||||
for (let k = scroll; k < scroll + paintHeight; k++) {
|
let lineStart = from || scroll;
|
||||||
|
let lineEnd = toExclusive || scroll + paintHeight;
|
||||||
|
for (let k = lineStart; k < lineEnd; k++) {
|
||||||
drawTextLineAbsolute(k, (k == cursorRow) ? scrollHor : 0);
|
drawTextLineAbsolute(k, (k == cursorRow) ? scrollHor : 0);
|
||||||
}
|
}
|
||||||
gotoText();
|
gotoText();
|
||||||
@@ -260,12 +262,10 @@ function appendLine() {
|
|||||||
cursorCol = 0;
|
cursorCol = 0;
|
||||||
cursoringCol = cursorCol;
|
cursoringCol = cursorCol;
|
||||||
|
|
||||||
if (cursorRow >= windowHeight - scrollPeek) {
|
if (cursorRow >= windowHeight - scrollPeek)
|
||||||
scroll += 1;
|
scroll += 1;
|
||||||
drawLineNumbers();
|
|
||||||
}
|
|
||||||
|
|
||||||
drawTextbuffer();
|
drawTextbuffer(); drawLineNumbers();
|
||||||
}
|
}
|
||||||
|
|
||||||
function backspaceOnce() {
|
function backspaceOnce() {
|
||||||
@@ -274,13 +274,24 @@ function backspaceOnce() {
|
|||||||
let s1 = textbuffer[cursorRow - 1];
|
let s1 = textbuffer[cursorRow - 1];
|
||||||
let s2 = textbuffer[cursorRow];
|
let s2 = textbuffer[cursorRow];
|
||||||
textbuffer.splice(cursorRow - 1, 2, s1+s2);
|
textbuffer.splice(cursorRow - 1, 2, s1+s2);
|
||||||
cursorMoveRelative(0,-1); cursorMoveRelative(Number.MAX_SAFE_INTEGER, 0); cursorHorAbsolute(s1.length);
|
// move cursor and possibly scrollHor
|
||||||
|
cursorMoveRelative(0,-1); cursorMoveRelative(Number.MAX_SAFE_INTEGER, 0);
|
||||||
|
cursorHorAbsolute(s1.length);
|
||||||
|
cursoringCol = cursorCol;
|
||||||
|
// end of repositioning
|
||||||
|
drawTextbuffer(cursorRow);
|
||||||
|
drawLineNumbers();
|
||||||
}
|
}
|
||||||
// delete a character
|
// delete a character
|
||||||
else if (cursorCol > 0) {
|
else if (cursorCol > 0) {
|
||||||
let s = textbuffer[cursorRow].substring(0);
|
let s = textbuffer[cursorRow].substring(0);
|
||||||
textbuffer[cursorRow] = s.substring(0, cursorCol - 1) + s.substring(cursorCol);
|
textbuffer[cursorRow] = s.substring(0, cursorCol - 1) + s.substring(cursorCol);
|
||||||
|
// identical to con.KEY_LEFT
|
||||||
|
cursoringCol = cursorCol - 1;
|
||||||
|
if (cursoringCol < 0) cursoringCol = 0;
|
||||||
cursorMoveRelative(-1,0);
|
cursorMoveRelative(-1,0);
|
||||||
|
// end of con.KEY_LEFT
|
||||||
|
drawTextLineAbsolute(cursorRow, scrollHor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,10 +424,11 @@ while (!exit) {
|
|||||||
displayBulletin(`Wrote ${textbuffer.length} lines`);
|
displayBulletin(`Wrote ${textbuffer.length} lines`);
|
||||||
}
|
}
|
||||||
else if (key == con.KEY_BACKSPACE) { // Bksp
|
else if (key == con.KEY_BACKSPACE) { // Bksp
|
||||||
backspaceOnce(); drawLnCol(); gotoText();
|
backspaceOnce();
|
||||||
|
drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
else if (key == con.KEY_RETURN) { // Return
|
else if (key == con.KEY_RETURN) { // Return
|
||||||
appendLine(); drawLineNumbers(); drawLnCol(); gotoText();
|
appendLine(); drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
else if (key == con.KEY_LEFT) {
|
else if (key == con.KEY_LEFT) {
|
||||||
cursoringCol = cursorCol - 1;
|
cursoringCol = cursorCol - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user