Merge pull request #6039 from overleaf/ta-synctex-cursor-position-init

Fix Cursor Position Tracking for Synctex

GitOrigin-RevId: 6df703812f3efa2163b953aab82f32e174919179
This commit is contained in:
Timothée Alby 2021-12-14 14:24:32 +01:00 committed by Copybot
parent f7275a6c4b
commit c1c0f1fe4a

View file

@ -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()