edit.js: vert scroll fixed, but not PgDn; hor scroll is still broken

This commit is contained in:
minjaesong
2021-04-18 17:41:56 +09:00
parent 6a1ce46f7b
commit aede935250

View File

@@ -296,7 +296,7 @@ function cursorMoveRelative(odx, ody) {
else if (cursorCol + dx < 0) else if (cursorCol + dx < 0)
dx = -cursorCol; dx = -cursorCol;
if (cursorRow + dy > textbuffer.length) if (cursorRow + dy > textbuffer.length - 1)
dy = textbuffer.length - cursorRow; dy = textbuffer.length - cursorRow;
else if (cursorRow + dy < 0) else if (cursorRow + dy < 0)
dy = -cursorRow; dy = -cursorRow;
@@ -328,23 +328,25 @@ function cursorMoveRelative(odx, ody) {
// update vertical scroll stats // update vertical scroll stats
if (dy != 0) { if (dy != 0) {
if (ny > paintHeight) { let stride = paintHeight - 1 - scrollPeek;
scroll += (ny - paintHeight - scrollPeek);
ny = paintHeight - scrollPeek if (ny > stride) {
scroll += ny - stride;
ny = stride;
} }
else if (ny < 0) { else if (ny < 0 + scrollPeek) {
let scrollToTop = (scroll - dy <= 0); scroll += ny - scrollPeek; // ny is less than zero
if (scrollToTop) { ny = 1;
// scroll to the top?
if (scroll <= -1) { // scroll of -1 would result to show "Line 0" on screen
scroll = 0; 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 // update screendraw
if (oldScroll != scroll) { if (oldScroll != scroll) {