diff --git a/src/components/editor/document-renderer-pane/document-render-pane.tsx b/src/components/editor/document-renderer-pane/document-render-pane.tsx index 4d07d0279..3e6d61dde 100644 --- a/src/components/editor/document-renderer-pane/document-render-pane.tsx +++ b/src/components/editor/document-renderer-pane/document-render-pane.tsx @@ -52,20 +52,24 @@ export const DocumentRenderPane: React.FC 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 return (
+ ref={renderer} onScroll={userScroll} onMouseEnter={onMakeScrollSource}>
= ({ 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)