fixing edit.js wip

This commit is contained in:
minjaesong
2021-09-23 17:58:31 +09:00
parent d0196786b4
commit 3a1bb48514

View File

@@ -229,17 +229,21 @@ function writeout() {
// KEYBOARDING FUNCTIONS //
function hitCtrlS() {
sys.poke(-40, 1);
sys.poke(-40, 255);
return (sys.peek(-41) == 47 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
}
function hitCtrlX() {
sys.poke(-40, 1);
return (sys.peek(-41) == 52 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
function hitCtrlQ() {
sys.poke(-40, 255);
return (sys.peek(-41) == 45 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
}
function hitAny() {
sys.poke(-40, 1);
sys.poke(-40, 255);sys.spin();
return sys.peek(-41) != 0;
}
function getch() {
sys.poke(-40, 255);
return sys.peek(-41);
}
function insertChar(code, row, col) {
if (textbuffer[row] === undefined)
@@ -427,74 +431,83 @@ else {
}
while (!exit) {
let key = con.getch();
let key = getch();
// TODO: either implement the new strobing-getch() by yourself or modify the sys.getch() so that CTRL-alph would return correct numbers
if (key != 0) {
if (bulletinShown) dismissBulletin();
serial.println(`getch = ${key}`)
if (key == 17) // Ctrl-Q
exit = true;
else if (key == 19 && !bulletinShown) {
writeout();
displayBulletin(`Wrote ${textbuffer.length} lines`);
}
else if (key == con.KEY_BACKSPACE) { // Bksp
backspaceOnce();
drawLnCol(); gotoText();
}
else if (key == con.KEY_RETURN) { // Return
appendLine(); drawLnCol(); gotoText();
}
else if (key == con.KEY_LEFT) {
cursoringCol = cursorCol - 1;
if (cursoringCol < 0) cursoringCol = 0;
cursorMoveRelative(-1,0);
}
else if (key == con.KEY_RIGHT) {
cursoringCol = cursorCol + 1;
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
cursorMoveRelative(1,0);
}
else if (key == con.KEY_UP) {
cursorMoveRelative(0,-1);
}
else if (key == con.KEY_DOWN) {
cursorMoveRelative(0,1);
}
else if (key == con.KEY_PAGE_UP) {
cursorMoveRelative(0, -paintHeight + scrollPeek);
}
else if (key == con.KEY_PAGE_DOWN) {
cursorMoveRelative(0, paintHeight - scrollPeek);
}
else if (key == con.KEY_HOME) {
cursoringCol = 0;
cursorMoveRelative(-BIG_STRIDE, 0);
}
else if (key == con.KEY_END) {
cursoringCol = textbuffer[cursorRow].length;
cursorMoveRelative(BIG_STRIDE, 0);
}
else if (key == con.KEY_TAB) { // insert spaces appropriately
let tabsize = TAB_SIZE - (cursorCol % TAB_SIZE);
if (bulletinShown) dismissBulletin();
for (let k = 0; k < tabsize; k++) {
insertChar(32, cursorRow, cursorCol);
sys.poke(-40, 255)
serial.println(`strobe: ${sys.peek(-41)}\t${sys.peek(-42)}`)
if (hitCtrlQ()) // Ctrl-Q
exit = true;
else if (hitCtrlS() && !bulletinShown) {
writeout();
displayBulletin(`Wrote ${textbuffer.length} lines`);
}
else if (key == con.KEY_BACKSPACE) { // Bksp
backspaceOnce();
drawLnCol(); gotoText();
}
else if (key == con.KEY_RETURN) { // Return
appendLine(); drawLnCol(); gotoText();
}
else if (key == con.KEY_LEFT) {
cursoringCol = cursorCol - 1;
if (cursoringCol < 0) cursoringCol = 0;
cursorMoveRelative(-1,0);
}
else if (key == con.KEY_RIGHT) {
cursoringCol = cursorCol + 1;
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
cursorMoveRelative(1,0);
}
else if (key == con.KEY_UP) {
cursorMoveRelative(0,-1);
}
else if (key == con.KEY_DOWN) {
cursorMoveRelative(0,1);
}
else if (key == con.KEY_PAGE_UP) {
cursorMoveRelative(0, -paintHeight + scrollPeek);
}
else if (key == con.KEY_PAGE_DOWN) {
cursorMoveRelative(0, paintHeight - scrollPeek);
}
else if (key == con.KEY_HOME) {
cursoringCol = 0;
cursorMoveRelative(-BIG_STRIDE, 0);
}
else if (key == con.KEY_END) {
cursoringCol = textbuffer[cursorRow].length;
cursorMoveRelative(BIG_STRIDE, 0);
}
else if (key == con.KEY_TAB) { // insert spaces appropriately
let tabsize = TAB_SIZE - (cursorCol % TAB_SIZE);
for (let k = 0; k < tabsize; k++) {
insertChar(32, cursorRow, cursorCol);
// identical to con.KEY_RIGHT
cursoringCol = cursorCol + 1;
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
cursorMoveRelative(1,0);
// end of con.KEY_RIGHT
}
drawTextLineAbsolute(cursorRow, scrollHor); drawLnCol(); gotoText();
}
else if (key >= 32 && key < 128) { // printables (excludes \n)
insertChar(key, cursorRow, cursorCol);
// identical to con.KEY_RIGHT
cursoringCol = cursorCol + 1;
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
cursorMoveRelative(1,0);
// end of con.KEY_RIGHT
drawTextLineAbsolute(cursorRow, scrollHor); drawLnCol(); gotoText();
}
drawTextLineAbsolute(cursorRow, scrollHor); drawLnCol(); gotoText();
}
else if (key >= 32 && key < 128) { // printables (excludes \n)
insertChar(key, cursorRow, cursorCol);
// identical to con.KEY_RIGHT
cursoringCol = cursorCol + 1;
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
cursorMoveRelative(1,0);
// end of con.KEY_RIGHT
drawTextLineAbsolute(cursorRow, scrollHor); drawLnCol(); gotoText();
}
}