Disable "Go to code location in PDF" button for non-TeX files (#23751)

GitOrigin-RevId: 9a51252e2df6e52532d0cd787a8fd744af41ed95
This commit is contained in:
Alf Eaton
2025-02-25 09:25:24 +00:00
committed by Copybot
parent 4e0b022aed
commit 2ba05cde40
2 changed files with 15 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ import { useEditorManagerContext } from '@/features/ide-react/context/editor-man
import useEventListener from '@/shared/hooks/use-event-listener'
import { PdfScrollPosition } from '@/shared/hooks/use-pdf-scroll-position'
import { CursorPosition } from '@/features/ide-react/types/cursor-position'
import { isValidTeXFile } from '@/main/is-valid-tex-file'
function GoToCodeButton({
position,
@@ -111,12 +112,12 @@ function GoToPdfButton({
syncToPdf,
syncToPdfInFlight,
isDetachLayout,
hasSingleSelectedDoc,
canSyncToPdf,
}: {
cursorPosition: CursorPosition | null
syncToPdf: (cursorPosition: CursorPosition | null) => void
syncToPdfInFlight: boolean
hasSingleSelectedDoc: boolean
canSyncToPdf: boolean
isDetachLayout?: boolean
}) {
const { t } = useTranslation()
@@ -168,7 +169,7 @@ function GoToPdfButton({
variant="secondary"
size="sm"
onClick={() => syncToPdf(cursorPosition)}
disabled={syncToPdfInFlight || !cursorPosition || !hasSingleSelectedDoc}
disabled={syncToPdfInFlight || !canSyncToPdf}
className={buttonClasses}
aria-label={t('go_to_code_location_in_pdf')}
bs3Props={{
@@ -198,7 +199,8 @@ function PdfSynctexControls() {
const { selectedEntities } = useFileTreeData()
const { findEntityByPath, dirname, pathInFolder } = useFileTreePathContext()
const { getCurrentDocumentId, openDocWithId } = useEditorManagerContext()
const { getCurrentDocumentId, openDocWithId, openDocName } =
useEditorManagerContext()
const [cursorPosition, setCursorPosition] = useState<CursorPosition | null>(
() => {
@@ -438,6 +440,12 @@ function PdfSynctexControls() {
return null
}
const canSyncToPdf: boolean =
hasSingleSelectedDoc &&
cursorPosition &&
openDocName &&
isValidTeXFile(openDocName)
if (detachRole === 'detacher') {
return (
<>
@@ -446,7 +454,7 @@ function PdfSynctexControls() {
syncToPdf={syncToPdf}
syncToPdfInFlight={syncToPdfInFlight}
isDetachLayout
hasSingleSelectedDoc={hasSingleSelectedDoc}
canSyncToPdf={canSyncToPdf}
/>
</>
)
@@ -468,7 +476,7 @@ function PdfSynctexControls() {
cursorPosition={cursorPosition}
syncToPdf={syncToPdf}
syncToPdfInFlight={syncToPdfInFlight}
hasSingleSelectedDoc={hasSingleSelectedDoc}
canSyncToPdf={canSyncToPdf}
/>
<GoToCodeButton

View File

@@ -6,6 +6,7 @@ export const mockScope = () => ({
pdfViewer: 'pdfjs',
},
editor: {
open_doc_name: 'main.tex',
sharejs_doc: {
doc_id: 'test-doc',
getSnapshot: () => 'some doc content',