Skip to content

Commit c3ce123

Browse files
committed
Handle reset when console buffer is cleared
1 parent 1a55851 commit c3ce123

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

plugins/editor/scroller.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,26 @@ var Scroller = function() {
4545
};
4646

4747
Scroller.prototype.setLines = function(newLines) {
48+
// console.log(newLines);
4849
var len = newLines.length;
50+
this.lines = newLines;
4951
if(this.sticky){
5052
this.startPosition = Math.max(0, len - this.minVisible);
53+
}else if(newLines.length === 1 && newLines[0].length === 0){
54+
// ^^ `lines` is reset to an array with one empty line. ugh.
55+
56+
// handle the reset case when lines is replaced with an empty array
57+
// we don't have a direct event that can call this
58+
this.reset();
5159
}
52-
this.lines = newLines;
5360
this.dirty = true;
5461
};
5562

56-
Scroller.prototype.reset = function(clearLines){
57-
this.visibleCount = this.minVisible;
63+
Scroller.prototype.reset = function(){
64+
this.startPosition = Math.max(0, this.lines.length - this.minVisible);
65+
this.jumpToBottom = true;
5866
this.sticky = true;
5967
this.dirty = true;
60-
if(clearLines){
61-
this.lines = [];
62-
this.startPosition = 0;
63-
}
64-
if(this.console){
65-
this.animateRequest = requestAnimationFrame(this.refresh);
66-
}
6768
};
6869

6970
Scroller.prototype.requestRefresh = function(){
@@ -110,14 +111,12 @@ Scroller.prototype.onScroll = function(){
110111
var height = this.console.offsetHeight;
111112
var scrollHeight = this.console.scrollHeight;
112113
var scrollTop = this.console.scrollTop;
113-
if(scrollTop < 15 && this.startPosition > 0){
114+
if(!this.jumpToBottom && scrollTop < 15 && this.startPosition > 0){
114115
this.expand();
115-
}else if(scrollTop + height > scrollHeight - 15){
116-
if(!this.sticky){
117-
this.jumpToBottom = true;
118-
this.sticky = true;
119-
this.dirty = true;
120-
}
116+
}else if(!this.sticky && scrollTop + height > scrollHeight - 15){
117+
this.jumpToBottom = true;
118+
this.sticky = true;
119+
this.dirty = true;
121120
}
122121

123122
if(this.dirty){

0 commit comments

Comments
 (0)