From 2fff1c473f018329dc26f28a95b2c9b9420fa145 Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 7 Jan 2021 20:09:54 +0000 Subject: [PATCH] change in buffer management --- src/static/js/scroll.js | 14 +++++--------- tests/frontend/specs/pageupdown.js | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/static/js/scroll.js b/src/static/js/scroll.js index 8c9661843..31a9dccd2 100644 --- a/src/static/js/scroll.js +++ b/src/static/js/scroll.js @@ -354,15 +354,15 @@ Scroll.prototype.movePage = function (direction) { // if the buffer of a fixed value isn't working as intended const linePosition = caretPosition.getPosition(); const buffer = 25; - - let pixelsToScroll = viewport.top - viewport.bottom; - + // we need to remember that lineoffset needs to be removed too.. + let offset = linePosition.bottom - viewport.top; + let pixelsToScroll = viewport.top - viewport.bottom + offset; if (direction === 'up') { // buffer pixels unscrolled our safety net here. You can't use the current or previous // line height because it might be a very long line.. - pixelsToScroll = -Math.abs(pixelsToScroll + buffer); + pixelsToScroll = -Math.abs(pixelsToScroll + buffer/2); } else { - pixelsToScroll = Math.abs(pixelsToScroll + buffer); + pixelsToScroll = Math.abs(pixelsToScroll + buffer/2); } this.outerWin.scrollBy(0, pixelsToScroll); @@ -371,12 +371,10 @@ Scroll.prototype.movePage = function (direction) { Scroll.prototype.getFirstVisibleCharacter = function (direction, rep) { const viewport = this._getViewPortTopBottom(); - console.log('viewport', viewport); const editor = parent.document.getElementsByTagName('iframe'); const lines = $(editor).contents().find('div'); // const currentLine = $(editor).contents().find('#innerdocbody'); const currentLine = rep.lines.atIndex(rep.selEnd[0]); - console.log('currentLine', currentLine); const modifiedRep = {}; modifiedRep.selStart = []; modifiedRep.selEnd = []; @@ -389,7 +387,6 @@ Scroll.prototype.getFirstVisibleCharacter = function (direction, rep) { // is each line in the viewport? if (lineBase > viewport.top) { - top.console.log('returning', index); modifiedRep.selEnd[0] = index; modifiedRep.selStart[0] = index; modifiedRep.selEnd[1] = 0; @@ -405,7 +402,6 @@ Scroll.prototype.getFirstVisibleCharacter = function (direction, rep) { // oh dear, looks like the original line is still the first in the viewport.. // we will need to move the rep X chars within that original position. - console.log('CANT SEE NEXT LiNE!'); modifiedRep.selStart[0] = rep.selStart[0]; modifiedRep.selEnd[0] = rep.selEnd[0]; diff --git a/tests/frontend/specs/pageupdown.js b/tests/frontend/specs/pageupdown.js index c0edcf1e8..8d9793f7f 100644 --- a/tests/frontend/specs/pageupdown.js +++ b/tests/frontend/specs/pageupdown.js @@ -357,7 +357,7 @@ describe('Shift Page Up/Down', function () { }, }); }); -/* + it('highlights lines on shift page down and releases them on page up', async function () { await helper.edit('xxx', 1); // caret is offset 6 @@ -391,8 +391,18 @@ describe('Shift Page Up/Down', function () { }); await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range'); }); -*/ - it('BROKEN JM TO FIX - highlights from end of document on page up then releases them on shift page down', async function () { + + it('Highlights from end of document on page up then releases them on shift page down', async function () { + // TODO: JM NEEDS HELP: Why isn't this working? It works if you do the same in browser.. + throw new Error("I NEED HELPZ PLZ") + + await helper.waitForPromise(() => helper.caretLineNumber() >= 201); + // make sure we're at bottom + helper.pageDown({ + pressAndHold: true, + }); + await helper.waitForPromise(() => helper.caretLineNumber() >= 201); + helper.pageUp({ shift: true, }); @@ -403,7 +413,6 @@ describe('Shift Page Up/Down', function () { }); await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Caret'); }); -/* it('highlights from end of document on page up twice and retains on single page down', async function () { helper.pageUp({ shift: true, @@ -451,7 +460,7 @@ describe('Shift Page Up/Down', function () { xit('highlights (a few lines) range backwards (rep.selFocusAtStart) then hit page down, selStart should be initial selEnd and selEnd further than original selEnd', async function () { throw new Error("JM TO DO") }); -*/ + }); describe('Press and Hold Page Up/Down', function () {