Desktop: Fixes #4797 (partially): Scroll position is not remembered in Markdown editor (#4806)

This commit is contained in:
Roman Musin authored and GitHub committed 2021-04-25 09:52:05 +01:00
1 parent a4854fcde8
commit f87ff54e3d
1 file changed
+6 -1
@@ -70,9 +70,14 @@ export function useScrollHandler(editorRef: any, webviewRef: any, onScroll: Func
if (editorRef.current) { if (editorRef.current) {
const percent = editorRef.current.getScrollPercent(); const percent = editorRef.current.getScrollPercent();
if (!isNaN(percent)) {
// when switching to another note, the percent can sometimes be NaN
// this is coming from `gui/NoteEditor/NoteBody/CodeMirror/utils/useScrollUtils.ts`
// when CodeMirror returns scroll info with heigth == clientHeigth
// https://github.com/laurent22/joplin/issues/4797
setViewerPercentScroll(percent); setViewerPercentScroll(percent);
} }
}
}, [setViewerPercentScroll]); }, [setViewerPercentScroll]);
const resetScroll = useCallback(() => { const resetScroll = useCallback(() => {