Skip to content

Commit d9177a7

Browse files
committed
Merge pull request #397 from airodactyl/fix-scrolling
Fix scrolling
2 parents 588c430 + e6fa455 commit d9177a7

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

common/content/buffer.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ const Buffer = Module("buffer", {
703703
* Scrolls to the bottom of the current buffer.
704704
*/
705705
scrollBottom: function () {
706-
Buffer.scrollToPercent(null, 100);
706+
Buffer.scrollElemToPercent(null, null, 100);
707707
},
708708

709709
/**
@@ -720,7 +720,7 @@ const Buffer = Module("buffer", {
720720
* Scrolls to the top of the current buffer.
721721
*/
722722
scrollEnd: function () {
723-
Buffer.scrollToPercent(100, null);
723+
Buffer.scrollElemToPercent(null, 100, null);
724724
},
725725

726726
/**
@@ -747,21 +747,19 @@ const Buffer = Module("buffer", {
747747
* Scrolls the buffer vertically 'scroll' lines.
748748
*
749749
* @param {boolean} direction The direction to scroll. If true then
750-
* scroll up and if false scroll down.
750+
* scroll down and if false scroll up.
751751
* @param {number} count The multiple of 'scroll' lines to scroll.
752752
* @optional
753753
*/
754754
scrollByScrollSize: function (direction, count) {
755755
direction = direction ? 1 : -1;
756756
count = count || 1;
757-
let win = Buffer.findScrollableWindow();
758-
759-
Buffer.checkScrollYBounds(win, direction);
757+
let elem = Buffer.findScrollable(direction, false);
760758

761759
if (options["scroll"] > 0)
762760
this.scrollLines(options["scroll"] * direction);
763761
else // scroll half a page down in pixels
764-
win.scrollBy(0, win.innerHeight / 2 * direction);
762+
elem.scrollTop += Buffer.findScrollableWindow().innerHeight / 2 * direction;
765763
},
766764

767765
_scrollByScrollSize: function _scrollByScrollSize(count, direction) {
@@ -777,7 +775,7 @@ const Buffer = Module("buffer", {
777775
* @param {number} y The vertical page percentile.
778776
*/
779777
scrollToPercent: function (x, y) {
780-
Buffer.scrollToPercent(x, y);
778+
Buffer.scrollElemToPercent(null, x, y);
781779
},
782780

783781
/**
@@ -795,14 +793,14 @@ const Buffer = Module("buffer", {
795793
* Scrolls the current buffer laterally to its leftmost.
796794
*/
797795
scrollStart: function () {
798-
Buffer.scrollToPercent(0, null);
796+
Buffer.scrollElemToPercent(null, 0, null);
799797
},
800798

801799
/**
802800
* Scrolls the current buffer vertically to the top.
803801
*/
804802
scrollTop: function () {
805-
Buffer.scrollToPercent(null, 0);
803+
Buffer.scrollElemToPercent(null, null, 0);
806804
},
807805

808806
// TODO: allow callback for filtering out unwanted frames? User defined?
@@ -1069,7 +1067,7 @@ const Buffer = Module("buffer", {
10691067
return win;
10701068
},
10711069

1072-
findScrollable: function findScrollable(dir, horizontal) {
1070+
findScrollable: function findScrollable(dir = 0, horizontal) {
10731071
let pos = "scrollTop", maxPos = "scrollTopMax", clientSize = "clientHeight";
10741072
if (horizontal)
10751073
pos = "scrollLeft", maxPos = "scrollLeftMax", clientSize = "clientWidth";
@@ -1081,7 +1079,7 @@ const Buffer = Module("buffer", {
10811079
for (; elem && elem.parentNode instanceof Element; elem = elem.parentNode) {
10821080
if (elem[clientSize] == 0)
10831081
continue;
1084-
if (dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] < elem[maxPos])
1082+
if (dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] < elem[maxPos] || dir == 0 && elem[maxPos] > 0)
10851083
break;
10861084
}
10871085
return elem;

0 commit comments

Comments
 (0)