From 92450e071ded10693faf46ae2ee1138abc16f3e8 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 28 Dec 2020 09:34:58 +0000 Subject: [PATCH] much better ux --- src/static/js/ace2_inner.js | 9 ++++----- src/static/js/scroll.js | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index ddde978dd..a2fd165a8 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -3061,8 +3061,8 @@ function Ace2Inner() { if (isPageUp) { top.console.log('page up'); // go to the top of the visible content - rep.selStart[0] -= visibleLineRange[1] - visibleLineRange[0]; - rep.selEnd[0] -= visibleLineRange[1] - visibleLineRange[0]; + rep.selStart[0] -= visibleLineRange[1] - visibleLineRange[0] + 1; + rep.selEnd[0] -= visibleLineRange[1] - visibleLineRange[0] + 1; // if the new rep is beyond the viewport, put the caret on the last line if (rep.selStart[0] < 0) { rep.selStart = [0, 0]; @@ -3073,11 +3073,10 @@ function Ace2Inner() { if (isPageDown) { top.console.log('pag edown'); // go to the bottom of the last visible content - if(rep.selStart[0] === 0){ + if (rep.selStart[0] === 0) { rep.selStart[0] += visibleLineRange[1] - visibleLineRange[0] - 1; rep.selEnd[0] += visibleLineRange[1] - visibleLineRange[0] - 1; - }else{ - // handle if we're on first line as it will do weird things. + } else { rep.selStart[0] += visibleLineRange[1] - visibleLineRange[0]; rep.selEnd[0] += visibleLineRange[1] - visibleLineRange[0]; } diff --git a/src/static/js/scroll.js b/src/static/js/scroll.js index 7639de728..1fd77cdfc 100644 --- a/src/static/js/scroll.js +++ b/src/static/js/scroll.js @@ -280,13 +280,12 @@ Scroll.prototype.scrollNodeVerticallyIntoView = function (rep, innerHeight, isPa // to inside of the viewport. Tested on IE, Firefox, Chrome in releases from 2015 until now // So, when the line scrolled gets outside of the viewport we let the browser handle it. const linePosition = caretPosition.getPosition(); - if (isPageUp) { // redraw entire page into view putting rep.selStart[0] at top left const distanceOfTopOfViewport = linePosition.top - viewport.top; const pixelsToScroll = distanceOfTopOfViewport - this._getPixelsRelativeToPercentageOfViewport(innerHeight, true); - this._scrollYPage(pixelsToScroll); + this._scrollYPage(pixelsToScroll - linePosition.height); return; }