mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 03:33:58 -05: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) {
|
||||
return
|
||||
}
|
||||
const resyncedScroll = Math.ceil(renderer.current.scrollTop) === lastScrollPosition.current
|
||||
if (resyncedScroll) {
|
||||
return
|
||||
}
|
||||
|
||||
const scrollTop = renderer.current.scrollTop
|
||||
|
||||
const beforeLineMark = lineMarks
|
||||
.filter(lineMark => lineMark.position <= scrollTop)
|
||||
const lineMarksBeforeScrollTop = lineMarks.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) =>
|
||||
prevLineMark.line >= currentLineMark.line ? prevLineMark : currentLineMark)
|
||||
|
||||
const afterLineMark = lineMarks
|
||||
.filter(lineMark => lineMark.position > scrollTop)
|
||||
const afterLineMark = lineMarksAfterScrollTop
|
||||
.reduce((prevLineMark, currentLineMark) =>
|
||||
prevLineMark.line < currentLineMark.line ? prevLineMark : currentLineMark)
|
||||
|
||||
|
@ -79,7 +83,7 @@ export const DocumentRenderPane: React.FC<DocumentRenderPaneProps & ScrollProps>
|
|||
|
||||
return (
|
||||
<div className={'bg-light flex-fill pb-5 flex-row d-flex w-100 h-100 overflow-y-scroll'}
|
||||
ref={renderer} onScroll={userScroll} onMouseEnter={onMakeScrollSource} >
|
||||
ref={renderer} onScroll={userScroll} onMouseEnter={onMakeScrollSource}>
|
||||
<div className={'col-md'}/>
|
||||
<MarkdownRenderer
|
||||
className={'flex-fill mb-3'}
|
||||
|
|
|
@ -87,7 +87,7 @@ export const EditorPane: React.FC<EditorPaneProps & ScrollProps> = ({ onContentC
|
|||
if (!editor || !scrollState) {
|
||||
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 newPositionRaw = startYOfLine + (heightOfLine * scrollState.scrolledPercentage / 100)
|
||||
const newPosition = Math.floor(newPositionRaw)
|
||||
|
|
Loading…
Reference in a new issue