diff --git a/services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts b/services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts index 1d71a50cb2..06ef1226fd 100644 --- a/services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts +++ b/services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts @@ -15,7 +15,6 @@ import { useEditorManagerContext } from '@/features/ide-react/context/editor-man import { useEditorOpenDocContext } from '@/features/ide-react/context/editor-open-doc-context' import useEventListener from '@/shared/hooks/use-event-listener' import { CursorPosition } from '@/features/ide-react/types/cursor-position' -import { isValidTeXFile } from '@/main/is-valid-tex-file' import { PdfScrollPosition } from '@/shared/hooks/use-pdf-scroll-position' import { showFileErrorToast, @@ -177,6 +176,12 @@ export default function useSynctex(): { positionRef.current = position }, [position]) + // SyncTeX only works for LaTeX projects (requires output.synctex.gz). + // Typst and Quarto do not produce this file. + const LATEX_EXTENSIONS_RE = /\.(tex|ltx|Rtex|Rnw)$/i + const rootDocPath = rootDocId ? pathInFolder(rootDocId) : null + const isLatexRootDoc = rootDocPath ? LATEX_EXTENSIONS_RE.test(rootDocPath) : false + const _syncToCode = useCallback( ({ position = positionRef.current, @@ -187,7 +192,7 @@ export default function useSynctex(): { selectText?: string visualOffset?: number }) => { - if (!position) { + if (!isLatexRootDoc || !position) { return } @@ -240,6 +245,7 @@ export default function useSynctex(): { }) }, [ + isLatexRootDoc, pdfFile, clsiServerId, projectId, @@ -284,10 +290,10 @@ export default function useSynctex(): { }, [selectedEntities, setHasSingleSelectedDoc]) const canSyncToPdf: boolean = + isLatexRootDoc && hasSingleSelectedDoc && - cursorPosition && - openDocName && - isValidTeXFile(openDocName) + !!cursorPosition && + !!openDocName return { syncToCode,