mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-04 10:41:14 +00:00
Keep scroll position if we scroll away from the bottom of the term
aka, scroll locking. Allows you to scroll back through logs without new log data dragging the scroll back down to the next entries as they come in.
This commit is contained in:
@@ -142,7 +142,12 @@ class Terminal extends React.Component {
|
||||
socket.onmessage = (event) => {
|
||||
log('pipe data', event.data.size);
|
||||
const input = ab2str(event.data);
|
||||
const scrolledToBottom = term.ydisp === term.ybase;
|
||||
const savedScrollPosition = term.ydisp;
|
||||
term.write(input);
|
||||
if (!scrolledToBottom) {
|
||||
this.scrollTo(savedScrollPosition);
|
||||
}
|
||||
};
|
||||
|
||||
this.socket = socket;
|
||||
@@ -154,6 +159,18 @@ class Terminal extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
scrollToBottom() {
|
||||
this.scrollTo(this.term.ybase);
|
||||
}
|
||||
|
||||
scrollTo(y) {
|
||||
if (!this.term) {
|
||||
return;
|
||||
}
|
||||
this.term.ydisp = y;
|
||||
this.term.refresh(0, this.term.rows - 1);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this._isMounted = true;
|
||||
if (this.props.connect) {
|
||||
@@ -173,6 +190,7 @@ class Terminal extends React.Component {
|
||||
const innerNode = ReactDOM.findDOMNode(component.innerFlex);
|
||||
this.term.open(innerNode);
|
||||
this.term.on('data', (data) => {
|
||||
this.scrollToBottom();
|
||||
if (this.socket) {
|
||||
this.socket.send(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user