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

- data-line attributes might not be directly under the body

- support checkbox preference `When scrolling, synchronize preview with editor`
This commit is contained in:
Baptiste Augrain
2018-12-24 11:25:41 +01:00
parent 9310e5e86c
commit e76bc72667
2 changed files with 11 additions and 7 deletions

View File

@@ -813,9 +813,7 @@ export default class MarkdownPreview extends React.Component {
}
scrollTo (targetRow) {
const blocks = this.getWindow().document.querySelectorAll(
'body>[data-line]'
)
const blocks = this.getWindow().document.querySelectorAll('body [data-line]')
for (let index = 0; index < blocks.length; index++) {
let block = blocks[index]

View File

@@ -13,13 +13,19 @@ class MarkdownSplitEditor extends React.Component {
this.value = props.value
this.focus = () => this.refs.code.focus()
this.reload = () => this.refs.code.reload()
this.userScroll = true
this.userScroll = props.config.preview.scrollSync
this.state = {
isSliderFocused: false,
codeEditorWidthInPercent: 50
}
}
componentDidUpdate (prevProps) {
if (this.props.config.preview.scrollSync !== prevProps.config.preview.scrollSync) {
this.userScroll = this.props.config.preview.scrollSync
}
}
handleCursorActivity (editor) {
if (this.userScroll) {
const previewDoc = _.get(this, 'refs.preview.refs.root.contentWindow.document')
@@ -31,7 +37,7 @@ class MarkdownSplitEditor extends React.Component {
top = 0
} else {
const blocks = []
for (const block of previewDoc.querySelectorAll('body>[data-line]')) {
for (const block of previewDoc.querySelectorAll('body [data-line]')) {
const l = parseInt(block.getAttribute('data-line'))
blocks.push({
@@ -87,7 +93,7 @@ class MarkdownSplitEditor extends React.Component {
const line = from + Math.floor((to - from) / 3)
const blocks = []
for (const block of previewDoc.querySelectorAll('body>[data-line]')) {
for (const block of previewDoc.querySelectorAll('body [data-line]')) {
const l = parseInt(block.getAttribute('data-line'))
blocks.push({
@@ -127,7 +133,7 @@ class MarkdownSplitEditor extends React.Component {
const previewTop = srcTop + delta
const blocks = []
for (const block of previewDoc.querySelectorAll('body>[data-line]')) {
for (const block of previewDoc.querySelectorAll('body [data-line]')) {
const top = block.offsetTop
blocks.push({