Fix render pane scrolling (#613)

This commit is contained in:
mrdrogdrog 2020-09-30 20:31:04 +02:00 committed by GitHub
parent 01a68b1efe
commit 5381f8ed90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,11 +97,15 @@ export const DocumentRenderPane: React.FC<DocumentRenderPaneProps & ScrollProps>
.reduce((prevLineMark, currentLineMark) => .reduce((prevLineMark, currentLineMark) =>
prevLineMark.line < currentLineMark.line ? prevLineMark : currentLineMark) prevLineMark.line < currentLineMark.line ? prevLineMark : currentLineMark)
const blockHeight = afterLineMark.position - beforeLineMark.position const componentHeight = afterLineMark.position - beforeLineMark.position
const distanceToBefore = scrollTop - beforeLineMark.position const distanceToBefore = scrollTop - beforeLineMark.position
const percentageRaw = (distanceToBefore / blockHeight) const percentageRaw = (distanceToBefore / componentHeight)
const percentage = Math.floor(percentageRaw * 100) const lineCount = afterLineMark.line - beforeLineMark.line
const newScrollState: ScrollState = { firstLineInView: beforeLineMark.line, scrolledPercentage: percentage } const line = Math.floor(lineCount * percentageRaw + beforeLineMark.line)
const lineHeight = componentHeight / lineCount
const innerScrolling = Math.floor((distanceToBefore % lineHeight) / lineHeight * 100)
const newScrollState: ScrollState = { firstLineInView: line, scrolledPercentage: innerScrolling }
onScroll(newScrollState) onScroll(newScrollState)
}, [lineMarks, onScroll]) }, [lineMarks, onScroll])