@@ -28,20 +28,8 @@ function Scroller(consoleElement) {
28
28
}
29
29
30
30
Scroller . prototype . _generateContent = function ( ) {
31
- const visible = this . visibleCount ;
32
31
return _ ( this . lines )
33
32
. 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
- } )
45
33
. map ( function ( line ) {
46
34
if ( line . length === 0 ) {
47
35
// insert a blank space to prevent pre omitting a trailing newline,
@@ -59,6 +47,10 @@ Scroller.prototype.setLines = function(newLines, offset) {
59
47
if ( this . sticky ) {
60
48
this . startPosition = Math . max ( this . lineOffset , this . lineCount ( ) - this . visibleCount ) ;
61
49
this . endPosition = this . lineCount ( ) ;
50
+ if ( this . endPosition <= this . visibleCount ) {
51
+ // follow text during initial 50 lines
52
+ this . jumpToBottom = true ;
53
+ }
62
54
} else if ( newLines . length === 1 && newLines [ 0 ] . length === 0 ) {
63
55
// ^^ `lines` is reset to an array with one empty line. ugh.
64
56
@@ -103,7 +95,7 @@ Scroller.prototype._renderVisible = function(){
103
95
}
104
96
this . console . innerHTML = this . _generateContent ( ) ;
105
97
if ( this . jumpToBottom ) {
106
- this . console . scrollTop = 2000 ;
98
+ this . console . scrollTop = 4000 ;
107
99
this . jumpToBottom = false ;
108
100
} else if ( ! this . sticky && this . startPosition > this . lineOffset && top === this . lineOffset ) {
109
101
//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(){
163
155
const height = this . console . offsetHeight ;
164
156
const scrollHeight = this . console . scrollHeight ;
165
157
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
+
166
162
if ( this . sticky ) {
167
- if ( scrollTop + height < scrollHeight - 30 ) {
163
+ if ( ! nearSticky ) {
168
164
this . sticky = false ;
169
165
}
170
166
} else {
171
- if ( scrollTop < 15 && this . startPosition > this . lineOffset ) {
167
+ if ( nearTop && this . startPosition > this . lineOffset ) {
172
168
this . expandTop ( ) ;
173
- } else if ( scrollTop + height > scrollHeight - 30 ) {
169
+ } else if ( nearBottom ) {
174
170
if ( this . endPosition < this . lineCount ( ) - 2 ) {
175
171
this . expandBottom ( ) ;
176
- } else {
172
+ } else if ( nearSticky ) {
177
173
this . jumpToBottom = true ;
178
174
this . sticky = true ;
179
175
this . dirty = true ;
180
176
}
181
177
}
182
178
}
183
179
180
+
181
+
184
182
if ( this . dirty && ! this . animateRequest ) {
185
183
this . animateRequest = requestAnimationFrame ( this . refresh ) ;
186
184
}
0 commit comments