Skip to content

Commit d8babb3

Browse files
committed
remove whitespace before text, improve scroll boundaries.
1 parent f6429d5 commit d8babb3

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/lib/scroller.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,8 @@ function Scroller(consoleElement) {
2828
}
2929

3030
Scroller.prototype._generateContent = function(){
31-
const visible = this.visibleCount;
3231
return _(this.lines)
3332
.slice(this.startPosition - this.lineOffset, this.endPosition - this.lineOffset)
34-
.thru(function(array){
35-
if(array.length < visible){
36-
// pad whitespace at top of array
37-
return _(new Array(visible - array.length))
38-
.fill('\u2009')
39-
.concat(array)
40-
.value();
41-
}else{
42-
return array;
43-
}
44-
})
4533
.map(function(line){
4634
if(line.length === 0){
4735
// insert a blank space to prevent pre omitting a trailing newline,
@@ -59,6 +47,10 @@ Scroller.prototype.setLines = function(newLines, offset) {
5947
if(this.sticky){
6048
this.startPosition = Math.max(this.lineOffset, this.lineCount() - this.visibleCount);
6149
this.endPosition = this.lineCount();
50+
if(this.endPosition <= this.visibleCount){
51+
// follow text during initial 50 lines
52+
this.jumpToBottom = true;
53+
}
6254
}else if(newLines.length === 1 && newLines[0].length === 0){
6355
// ^^ `lines` is reset to an array with one empty line. ugh.
6456

@@ -103,7 +95,7 @@ Scroller.prototype._renderVisible = function(){
10395
}
10496
this.console.innerHTML = this._generateContent();
10597
if(this.jumpToBottom){
106-
this.console.scrollTop = 2000;
98+
this.console.scrollTop = 4000;
10799
this.jumpToBottom = false;
108100
}else if(!this.sticky && this.startPosition > this.lineOffset && top === this.lineOffset){
109101
//cover the situation where the window was fully scrolled faster than expand could keep up and locked to the top
@@ -163,24 +155,30 @@ Scroller.prototype._onScroll = function(){
163155
const height = this.console.offsetHeight;
164156
const scrollHeight = this.console.scrollHeight;
165157
const scrollTop = this.console.scrollTop;
158+
const nearTop = scrollTop < 100;
159+
const nearBottom = scrollTop + height > scrollHeight - 100;
160+
const nearSticky = scrollTop + height > scrollHeight - 10;
161+
166162
if(this.sticky){
167-
if(scrollTop + height < scrollHeight - 30){
163+
if(!nearSticky){
168164
this.sticky = false;
169165
}
170166
}else{
171-
if(scrollTop < 15 && this.startPosition > this.lineOffset){
167+
if(nearTop && this.startPosition > this.lineOffset){
172168
this.expandTop();
173-
}else if(scrollTop + height > scrollHeight - 30){
169+
}else if(nearBottom){
174170
if(this.endPosition < this.lineCount() - 2){
175171
this.expandBottom();
176-
}else{
172+
}else if(nearSticky){
177173
this.jumpToBottom = true;
178174
this.sticky = true;
179175
this.dirty = true;
180176
}
181177
}
182178
}
183179

180+
181+
184182
if(this.dirty && !this.animateRequest){
185183
this.animateRequest = requestAnimationFrame(this.refresh);
186184
}

0 commit comments

Comments
 (0)