From c331397619141d26f41626170c5db1658a2c6abd Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 22 Apr 2021 17:47:27 +0900 Subject: [PATCH] edit.js: tab key impl --- assets/JS_INIT.js | 1 + assets/disk0/tvdos/bin/edit.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/JS_INIT.js b/assets/JS_INIT.js index f7e9ab1..d08bde3 100644 --- a/assets/JS_INIT.js +++ b/assets/JS_INIT.js @@ -387,6 +387,7 @@ con.KEY_PAGE_DOWN = 209; con.KEY_INSERT = 210; con.KEY_DELETE = 211; con.KEY_BACKSPACE = 8; +con.KEY_TAB = 9; con.KEY_RETURN = 13; con.getch = function() { return sys.readKey(); diff --git a/assets/disk0/tvdos/bin/edit.js b/assets/disk0/tvdos/bin/edit.js index 7e2f9dc..1f4342e 100644 --- a/assets/disk0/tvdos/bin/edit.js +++ b/assets/disk0/tvdos/bin/edit.js @@ -14,6 +14,7 @@ const COL_CARET_ROW = 81; const PAINT_START_X = 5; const PAINT_START_Y = 2; const BIG_STRIDE = 10000; +const TAB_SIZE = 4; let filename = undefined; @@ -171,7 +172,8 @@ function drawTextLineAbsolute(rowNumber, paintOffsetX) { con.color_pair(COL_TEXT, (rowNumber == cursorRow) ? COL_CARET_ROW : COL_BACK); for (let x = 0; x < paintWidth; x++) { - let text = textbuffer[rowNumber] + String.fromCharCode(254); + let text = textbuffer[rowNumber]; + if (rowNumber < textbuffer.length - 1) text += String.fromCharCode(254); let charCode = // nonexisting text row (undefined === textbuffer[rowNumber]) ? 0 : @@ -472,6 +474,19 @@ while (!exit) { 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