From 0253b548038b1ba55f14027221a5302839464031 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 28 Dec 2020 09:12:45 +0000 Subject: [PATCH] working page down and semi working page up --- src/static/js/= | 0 src/static/js/ace2_inner.js | 8 +++++--- src/static/js/scroll.js | 27 +++++++++++++++++++-------- src/static/js/viewportBottom | 0 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 src/static/js/= create mode 100644 src/static/js/viewportBottom diff --git a/src/static/js/= b/src/static/js/= new file mode 100644 index 000000000..e69de29bb diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 998b69496..9ac5d5a0b 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -3071,8 +3071,8 @@ function Ace2Inner() { if (isPageDown) { // go to the bottom of the last visible content - rep.selStart[0] += visibleLineRange[1]; - rep.selEnd[0] += visibleLineRange[1]; + rep.selStart[0] += visibleLineRange[1] - 1; + rep.selEnd[0] += visibleLineRange[1] - 1; // if the new rep is beyond the viewport, put the caret on the last line if (rep.selStart[0] > linesLength) { rep.selStart = [linesLength - 1, 0]; @@ -3082,7 +3082,9 @@ function Ace2Inner() { } updateBrowserSelectionFromRep(); // works - scroll.scrollNodeVerticallyIntoView(); // TODO: always slightly off... + scroll.scrollNodeVerticallyIntoView(null, null, isPageUp, isPageDown); + // TODO: always slightly off... + // TODO: if enough content is visible below show all of that content } // scroll to viewport when user presses arrow keys and caret is out of the viewport diff --git a/src/static/js/scroll.js b/src/static/js/scroll.js index b35575774..35bea04d7 100644 --- a/src/static/js/scroll.js +++ b/src/static/js/scroll.js @@ -273,24 +273,35 @@ Scroll.prototype._triggerScrollWithAnimation = // needed to be completely in view. If the value is greater than 0 and less than or equal to 1, // besides of scrolling the minimum needed to be visible, it scrolls additionally // (viewport height * scrollAmountWhenFocusLineIsOutOfViewport) pixels -Scroll.prototype.scrollNodeVerticallyIntoView = function (rep, innerHeight) { +Scroll.prototype.scrollNodeVerticallyIntoView = function (rep, innerHeight, isPageUp, isPageDown) { const viewport = this._getViewPortTopBottom(); // when the selection changes outside of the viewport the browser automatically scrolls the line // 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 (linePosition) { - // top.console.log('linepos', linePosition); + + if (isPageUp) { + // redraw entire page into view putting rep.selStart[0] at top left const distanceOfTopOfViewport = linePosition.top - viewport.top; - // TODO: Replace the below hack with the current caret location line height - const HACK = 20; - const distanceOfBottomOfViewport = viewport.bottom - linePosition.bottom - HACK; - // guessed value.. The above line needs to know the height of this element! + const pixelsToScroll = + distanceOfTopOfViewport - this._getPixelsRelativeToPercentageOfViewport(innerHeight, true); + this._scrollYPage(pixelsToScroll); + return; + } + + if (isPageDown) { + // redraw entire page into view putting rep.selStart[0] at top left + this._scrollYPage(linePosition.top); + return; + } + + if (linePosition) { + const distanceOfTopOfViewport = linePosition.top - viewport.top; + const distanceOfBottomOfViewport = viewport.bottom - linePosition.bottom; const caretIsAboveOfViewport = distanceOfTopOfViewport < 0; const caretIsBelowOfViewport = distanceOfBottomOfViewport < 0; - // top.console.log('isbelow', caretIsBelowOfViewport); if (caretIsAboveOfViewport) { const pixelsToScroll = distanceOfTopOfViewport - this._getPixelsRelativeToPercentageOfViewport(innerHeight, true); diff --git a/src/static/js/viewportBottom b/src/static/js/viewportBottom new file mode 100644 index 000000000..e69de29bb