mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +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:
@@ -813,9 +813,7 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scrollTo (targetRow) {
|
scrollTo (targetRow) {
|
||||||
const blocks = this.getWindow().document.querySelectorAll(
|
const blocks = this.getWindow().document.querySelectorAll('body [data-line]')
|
||||||
'body>[data-line]'
|
|
||||||
)
|
|
||||||
|
|
||||||
for (let index = 0; index < blocks.length; index++) {
|
for (let index = 0; index < blocks.length; index++) {
|
||||||
let block = blocks[index]
|
let block = blocks[index]
|
||||||
|
|||||||
@@ -13,13 +13,19 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
this.value = props.value
|
this.value = props.value
|
||||||
this.focus = () => this.refs.code.focus()
|
this.focus = () => this.refs.code.focus()
|
||||||
this.reload = () => this.refs.code.reload()
|
this.reload = () => this.refs.code.reload()
|
||||||
this.userScroll = true
|
this.userScroll = props.config.preview.scrollSync
|
||||||
this.state = {
|
this.state = {
|
||||||
isSliderFocused: false,
|
isSliderFocused: false,
|
||||||
codeEditorWidthInPercent: 50
|
codeEditorWidthInPercent: 50
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate (prevProps) {
|
||||||
|
if (this.props.config.preview.scrollSync !== prevProps.config.preview.scrollSync) {
|
||||||
|
this.userScroll = this.props.config.preview.scrollSync
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleCursorActivity (editor) {
|
handleCursorActivity (editor) {
|
||||||
if (this.userScroll) {
|
if (this.userScroll) {
|
||||||
const previewDoc = _.get(this, 'refs.preview.refs.root.contentWindow.document')
|
const previewDoc = _.get(this, 'refs.preview.refs.root.contentWindow.document')
|
||||||
@@ -31,7 +37,7 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
top = 0
|
top = 0
|
||||||
} else {
|
} else {
|
||||||
const blocks = []
|
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'))
|
const l = parseInt(block.getAttribute('data-line'))
|
||||||
|
|
||||||
blocks.push({
|
blocks.push({
|
||||||
@@ -87,7 +93,7 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
const line = from + Math.floor((to - from) / 3)
|
const line = from + Math.floor((to - from) / 3)
|
||||||
|
|
||||||
const blocks = []
|
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'))
|
const l = parseInt(block.getAttribute('data-line'))
|
||||||
|
|
||||||
blocks.push({
|
blocks.push({
|
||||||
@@ -127,7 +133,7 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
const previewTop = srcTop + delta
|
const previewTop = srcTop + delta
|
||||||
|
|
||||||
const blocks = []
|
const blocks = []
|
||||||
for (const block of previewDoc.querySelectorAll('body>[data-line]')) {
|
for (const block of previewDoc.querySelectorAll('body [data-line]')) {
|
||||||
const top = block.offsetTop
|
const top = block.offsetTop
|
||||||
|
|
||||||
blocks.push({
|
blocks.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user