Skip to content

Commit 1428911

Browse files
authored
Fix #37: ScrollToLine not scrolling to line when changed (#38)
1 parent 6e08104 commit 1428911

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/components/LazyLog/index.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface WebsocketOptions {
4747
* Set the time to wait between reconnects in seconds.
4848
* Default is 1s
4949
*/
50-
reconnectWait?: number
50+
reconnectWait?: number;
5151
}
5252

5353
export interface ErrorStatus extends Error {
@@ -427,7 +427,10 @@ export default class LazyLog extends Component<LazyLogProps, LazyLogState> {
427427

428428
// If follow is activated, and we're not currently searching, scroll to offset
429429
if (this.props.follow && !this.state.isSearching) {
430-
this.state.listRef?.current?.scrollToItem(this.state.scrollToIndex, "auto");
430+
this.state.listRef?.current?.scrollToItem(
431+
this.state.scrollToIndex,
432+
"auto"
433+
);
431434
this.state.listRef?.current?.forceUpdate();
432435
}
433436

@@ -452,6 +455,13 @@ export default class LazyLog extends Component<LazyLogProps, LazyLogState> {
452455
) {
453456
this.props.onHighlight(this.state.highlight!);
454457
}
458+
459+
if (
460+
this.props.scrollToLine &&
461+
prevProps.scrollToLine !== this.props.scrollToLine
462+
) {
463+
this.handleScrollToLine(this.props.scrollToLine);
464+
}
455465
}
456466

457467
componentWillUnmount() {
@@ -1143,15 +1153,21 @@ export default class LazyLog extends Component<LazyLogProps, LazyLogState> {
11431153
scrollOffset: options.scrollOffset,
11441154
});
11451155
// If there is an onScroll callback, call it.
1146-
if(this.props.onScroll) {
1156+
if (this.props.onScroll) {
11471157
const args = {
11481158
scrollTop: options.scrollOffset,
1149-
scrollHeight: this.getItemSize(0) * (rowCount === 0
1150-
? rowCount
1151-
: rowCount +
1152-
(this.props.extraLines || 0)),
1153-
clientHeight: this.calculateListHeight(height) as number
1154-
}
1159+
scrollHeight:
1160+
this.getItemSize(0) *
1161+
(rowCount === 0
1162+
? rowCount
1163+
: rowCount +
1164+
(this.props.extraLines ||
1165+
0)),
1166+
clientHeight:
1167+
this.calculateListHeight(
1168+
height
1169+
) as number,
1170+
};
11551171
this.props.onScroll(args);
11561172
}
11571173
}}

0 commit comments

Comments
 (0)