1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Sync Split Editor scroll position

This commit is contained in:
Sander Steenhuis
2018-02-09 03:19:04 +01:00
parent 46a733ba5b
commit c82eba05d1
3 changed files with 62 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ export default class CodeEditor extends React.Component {
this.loadStyleHandler = (e) => {
this.editor.refresh()
}
this.scrollHandler = _.debounce(this.handleScroll.bind(this), 100, {leading: false, trailing: true})
}
componentDidMount () {
@@ -107,6 +108,7 @@ export default class CodeEditor extends React.Component {
this.editor.on('blur', this.blurHandler)
this.editor.on('change', this.changeHandler)
this.editor.on('paste', this.pasteHandler)
this.editor.on('scroll', this.scrollHandler)
const editorTheme = document.getElementById('editorTheme')
editorTheme.addEventListener('load', this.loadStyleHandler)
@@ -126,6 +128,7 @@ export default class CodeEditor extends React.Component {
this.editor.off('blur', this.blurHandler)
this.editor.off('change', this.changeHandler)
this.editor.off('paste', this.pasteHandler)
this.editor.off('scroll', this.scrollHandler)
const editorTheme = document.getElementById('editorTheme')
editorTheme.removeEventListener('load', this.loadStyleHandler)
}
@@ -254,6 +257,12 @@ export default class CodeEditor extends React.Component {
}
}
handleScroll (e) {
if (this.props.onScroll) {
this.props.onScroll(e)
}
}
render () {
const { className, fontSize } = this.props
let fontFamily = this.props.fontFamily