mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 08:04:45 -04:00
Fix scroll bugs (#487)
* Check line presence before calculating position * Fix jump bug
This commit is contained in:
parent
8a9c2c923d
commit
52fb372b9b
2 changed files with 14 additions and 10 deletions
|
@ -52,20 +52,24 @@ export const DocumentRenderPane: React.FC<DocumentRenderPaneProps & ScrollProps>
|
||||||
if (!renderer.current || !lineMarks || !onScroll) {
|
if (!renderer.current || !lineMarks || !onScroll) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const resyncedScroll = Math.ceil(renderer.current.scrollTop) === lastScrollPosition.current
|
|
||||||
if (resyncedScroll) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const scrollTop = renderer.current.scrollTop
|
const scrollTop = renderer.current.scrollTop
|
||||||
|
|
||||||
const beforeLineMark = lineMarks
|
const lineMarksBeforeScrollTop = lineMarks.filter(lineMark => lineMark.position <= scrollTop)
|
||||||
.filter(lineMark => lineMark.position <= scrollTop)
|
if (lineMarksBeforeScrollTop.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineMarksAfterScrollTop = lineMarks.filter(lineMark => lineMark.position > scrollTop)
|
||||||
|
if (lineMarksAfterScrollTop.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const beforeLineMark = lineMarksBeforeScrollTop
|
||||||
.reduce((prevLineMark, currentLineMark) =>
|
.reduce((prevLineMark, currentLineMark) =>
|
||||||
prevLineMark.line >= currentLineMark.line ? prevLineMark : currentLineMark)
|
prevLineMark.line >= currentLineMark.line ? prevLineMark : currentLineMark)
|
||||||
|
|
||||||
const afterLineMark = lineMarks
|
const afterLineMark = lineMarksAfterScrollTop
|
||||||
.filter(lineMark => lineMark.position > scrollTop)
|
|
||||||
.reduce((prevLineMark, currentLineMark) =>
|
.reduce((prevLineMark, currentLineMark) =>
|
||||||
prevLineMark.line < currentLineMark.line ? prevLineMark : currentLineMark)
|
prevLineMark.line < currentLineMark.line ? prevLineMark : currentLineMark)
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ export const EditorPane: React.FC<EditorPaneProps & ScrollProps> = ({ onContentC
|
||||||
if (!editor || !scrollState) {
|
if (!editor || !scrollState) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const startYOfLine = editor.heightAtLine(scrollState.firstLineInView - 1, 'div')
|
const startYOfLine = editor.heightAtLine(scrollState.firstLineInView - 1, 'local')
|
||||||
const heightOfLine = (editor.lineInfo(scrollState.firstLineInView - 1).handle as { height: number }).height
|
const heightOfLine = (editor.lineInfo(scrollState.firstLineInView - 1).handle as { height: number }).height
|
||||||
const newPositionRaw = startYOfLine + (heightOfLine * scrollState.scrolledPercentage / 100)
|
const newPositionRaw = startYOfLine + (heightOfLine * scrollState.scrolledPercentage / 100)
|
||||||
const newPosition = Math.floor(newPositionRaw)
|
const newPosition = Math.floor(newPositionRaw)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue