From c1c0f1fe4a470ff55696e619f07a7e46c8924f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Tue, 14 Dec 2021 14:24:32 +0100 Subject: [PATCH] Merge pull request #6039 from overleaf/ta-synctex-cursor-position-init Fix Cursor Position Tracking for Synctex GitOrigin-RevId: 6df703812f3efa2163b953aab82f32e174919179 --- .../pdf-preview/components/pdf-synctex-controls.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js b/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js index 7f7cde6297..ed38d76349 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js @@ -14,6 +14,7 @@ import useIsMounted from '../../../shared/hooks/use-is-mounted' import useAbortController from '../../../shared/hooks/use-abort-controller' import useDetachState from '../../../shared/hooks/use-detach-state' import useDetachAction from '../../../shared/hooks/use-detach-action' +import localStorage from '../../../infrastructure/local-storage' function GoToCodeButton({ position, @@ -80,7 +81,7 @@ function GoToPdfButton({ bsStyle="default" bsSize="xs" onClick={() => syncToPdf(cursorPosition)} - disabled={syncToPdfInFlight} + disabled={syncToPdfInFlight || !cursorPosition} className={buttonClasses} aria-label={t('go_to_code_location_in_pdf')} > @@ -110,7 +111,12 @@ function PdfSynctexControls() { setHighlights, } = useCompileContext() - const [cursorPosition, setCursorPosition] = useState(null) + const [cursorPosition, setCursorPosition] = useState(() => { + const position = localStorage.getItem( + `doc.position.${ide.editorManager.getCurrentDocId()}` + ) + return position ? position.cursorPosition : null + }) const isMounted = useIsMounted()