Skip to content

Commit ad11ec5

Browse files
committed
Merge pull request #258 from parallaxinc/scroll-improvements
Improve scrolling functionality
2 parents 4217d20 + 5a70b03 commit ad11ec5

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/lib/scroller.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@ function Scroller(consoleElement) {
1515
this.console = consoleElement;
1616
this.expandDistance = 200;
1717

18-
//pre-bind functions and throttle expansion
18+
//pre-bind functions
1919
this.refresh = this._renderVisible.bind(this);
2020
this.scroll = this._onScroll.bind(this);
21-
this.expandTop = _.throttle(this._expandTop.bind(this), 150, {
22-
leading: true,
23-
trailing: true
24-
});
25-
this.expandBottom = _.throttle(this._expandBottom.bind(this), 150, {
26-
leading: true,
27-
trailing: true
28-
});
21+
this.expandTop = this._expandTop.bind(this);
22+
this.expandBottom = this._expandBottom.bind(this);
2923
}
3024

3125
Scroller.prototype._generateContent = function(){
@@ -48,8 +42,8 @@ Scroller.prototype.setLines = function(newLines, offset) {
4842
if(this.sticky){
4943
this.endPosition = this.lineCount();
5044
this.startPosition = Math.max(this.lineOffset, this.endPosition - this.visibleCount);
51-
if(this.endPosition <= this.visibleCount){
52-
// follow text during initial 50 lines
45+
if(this.endPosition <= this.visibleCount * 2){
46+
// follow text during initial lines (console can show up to twice the visibleCount when expanding)
5347
this.jumpToBottom = true;
5448
}
5549
}else if(newLines.length === 1 && newLines[0].length === 0){
@@ -89,7 +83,6 @@ Scroller.prototype.requestRefresh = function(){
8983
Scroller.prototype._renderVisible = function(){
9084
this.animateRequest = null;
9185
if(this.dirty && this.console){
92-
const top = this.console.scrollTop;
9386
if(this.sticky){
9487
this.endPosition = this.lineCount();
9588
this.startPosition = Math.max(this.lineOffset, this.endPosition - this.visibleCount);
@@ -98,9 +91,6 @@ Scroller.prototype._renderVisible = function(){
9891
if(this.jumpToBottom){
9992
this.console.scrollTop = 4000;
10093
this.jumpToBottom = false;
101-
}else if(!this.sticky && this.startPosition > this.lineOffset && top === this.lineOffset){
102-
//cover the situation where the window was fully scrolled faster than expand could keep up and locked to the top
103-
requestAnimationFrame(this.expandTop);
10494
}
10595
this.dirty = false;
10696
}

0 commit comments

Comments
 (0)