Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd0e387

Browse files
committed
make new scrollbar scroll to the highlighted line
1 parent cb5ea6a commit dd0e387

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/client/app/modules/components/file-viewer.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export class FileViewer extends React.Component {
4545
this.closePanel = this.closePanel.bind(this);
4646
this.toggleFullScreen = this.toggleFullScreen.bind(this);
4747
this.scrollToFocusedLine = this.scrollToFocusedLine.bind(this);
48-
this.scrollAmount = 0;
4948
}
5049

5150
closePanel() {
@@ -59,16 +58,17 @@ export class FileViewer extends React.Component {
5958
}
6059

6160
scrollToFocusedLine() {
62-
this.parentView.scrollTop = (this.props.line-1)*20 + 16 - screen.height/4;
61+
var scrollAmount = (this.props.line-1)*20 + 16 - screen.height/4;
62+
this.scrollbars.scrollTop(scrollAmount);
6363
}
6464

6565
render() {
6666
var {currentFilePath, line, className = ''} = this.props;
6767
return (
68-
<div className={"FullView " + className} ref={(ref) => this.parentView = this.parentView || ref}>
68+
<div className={"FullView " + className}>
6969
<CloseButton onClose={this.closePanel} toggleFull={this.toggleFullScreen}/>
7070
<Header filePath={currentFilePath} lno={line}/>
71-
<SuperFuckingAwesomeScrollbars>
71+
<SuperFuckingAwesomeScrollbars className="scrollParent" ref={(ref) => this.scrollbars = this.scrollbars || ref}>
7272
<div className="FullCode">
7373
<ConnectedCodeView
7474
key={currentFilePath}

src/client/app/modules/components/super-fucking-awesome-scrollbars.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import React, {Component} from 'react';
22
import { Scrollbars } from 'react-custom-scrollbars';
33

44
export class SuperFuckingAwesomeScrollbars extends Component {
5+
scrollTop(scrollAmount) {
6+
this.scrollbars.scrollTop(scrollAmount);
7+
}
8+
59
render() {
610
return (
711
<Scrollbars
812
autoHide={true}
913
autoHideTimeout={500}
1014
renderThumbHorizontal={props => <div {...props} className="thumb-horizontal"/>}
1115
renderThumbVertical={props => <div {...props} className="thumb-vertical"/>}
12-
{...this.props}>
16+
{...this.props}
17+
ref={(ref) => this.scrollbars = ref}>
1318
{this.props.children}
1419
</Scrollbars>
1520
);

0 commit comments

Comments
 (0)