1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 02:36:36 +00:00

Merge pull request #2405 from daiyam/fix-scroll

Better scroll sync between the editor and the preview in the SplitEditor
This commit is contained in:
Junyoung Choi
2020-07-20 19:48:29 +09:00
committed by GitHub
4 changed files with 229 additions and 56 deletions

View File

@@ -1145,17 +1145,18 @@ class MarkdownPreview extends React.Component {
/**
* @public
* @param {Number} targetRow
* @param {Number} targetLine
*/
scrollToRow(targetRow) {
scrollToLine(targetLine) {
const blocks = this.getWindow().document.querySelectorAll(
'body>[data-line]'
'body [data-line]'
)
for (let index = 0; index < blocks.length; index++) {
let block = blocks[index]
const row = parseInt(block.getAttribute('data-line'))
if (row > targetRow || index === blocks.length - 1) {
const line = parseInt(block.getAttribute('data-line'))
if (line > targetLine || index === blocks.length - 1) {
block = blocks[index - 1]
block != null && this.scrollTo(0, block.offsetTop)
break