From aede9352502c7fa0ceb1f57e8d9c72b525ce1816 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 18 Apr 2021 17:41:56 +0900 Subject: [PATCH] edit.js: vert scroll fixed, but not PgDn; hor scroll is still broken --- assets/disk0/tvdos/bin/edit.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/assets/disk0/tvdos/bin/edit.js b/assets/disk0/tvdos/bin/edit.js index e698a36..e8343dd 100644 --- a/assets/disk0/tvdos/bin/edit.js +++ b/assets/disk0/tvdos/bin/edit.js @@ -296,7 +296,7 @@ function cursorMoveRelative(odx, ody) { else if (cursorCol + dx < 0) dx = -cursorCol; - if (cursorRow + dy > textbuffer.length) + if (cursorRow + dy > textbuffer.length - 1) dy = textbuffer.length - cursorRow; else if (cursorRow + dy < 0) dy = -cursorRow; @@ -328,23 +328,25 @@ function cursorMoveRelative(odx, ody) { // update vertical scroll stats if (dy != 0) { - if (ny > paintHeight) { - scroll += (ny - paintHeight - scrollPeek); - ny = paintHeight - scrollPeek + let stride = paintHeight - 1 - scrollPeek; + + if (ny > stride) { + scroll += ny - stride; + ny = stride; } - else if (ny < 0) { - let scrollToTop = (scroll - dy <= 0); - if (scrollToTop) { + else if (ny < 0 + scrollPeek) { + scroll += ny - scrollPeek; // ny is less than zero + ny = 1; + + // scroll to the top? + if (scroll <= -1) { // scroll of -1 would result to show "Line 0" on screen scroll = 0; + ny = 0; } - else { - scroll += ny + paintHeight - scrollPeek; // ny is less than zero - } - ny = 0; } } - serial.println(`dY:${dy} nY:${ny} scrY:${scroll} row:${cursorRow}`); + serial.println(`dY:${dy} nY:${ny} scrY:${scroll} row:${cursorRow} | wDim:${paintHeight}R ${paintWidth}C peek:${scrollPeek}`); // update screendraw if (oldScroll != scroll) {