Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Commit

Permalink
Use a passive event listener for wheel events
Browse files Browse the repository at this point in the history
This improves the smoothness of scrolling.

Co-authored-by: Antonio Scandurra <[email protected]>
  • Loading branch information
Nathan Sobo and Antonio Scandurra committed Mar 5, 2018
1 parent f68cfb2 commit 21a1d82
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions xray_electron/lib/render_process/text_editor/text_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const $ = React.createElement;
class TextEditorContainer extends React.Component {
constructor(props) {
super(props);
this.onWheel = this.onWheel.bind(this);

const buffer = new xray.TextBuffer(1);
const editor = new xray.TextEditor(buffer, this.editorChanged.bind(this));
Expand All @@ -34,9 +35,13 @@ class TextEditorContainer extends React.Component {
width: element.offsetWidth,
height: element.offsetHeight
});

element.addEventListener('wheel', this.onWheel, {passive: true});
}

componentWillUnmount() {
const element = ReactDOM.findDOMNode(this);
element.removeEventListener('wheel', this.onWheel, {passive: true});
this.state.editor.destroy();
this.state.resizeObserver.disconnect();
}
Expand Down Expand Up @@ -68,12 +73,13 @@ class TextEditorContainer extends React.Component {
scrollTop,
width,
height,
frameState: this.computeFrameState(),
onWheel: event => {
this.setState({
scrollTop: Math.max(0, this.state.scrollTop + event.deltaY)
});
}
frameState: this.computeFrameState()
})
}

onWheel (event) {
this.setState({
scrollTop: Math.max(0, this.state.scrollTop + event.deltaY)
});
}
}
Expand Down

0 comments on commit 21a1d82

Please sign in to comment.