import classNames from 'classnames' import { memo, useCallback, useEffect, useState, useRef, useMemo } from 'react' import { useProjectContext } from '../../../shared/context/project-context' import { getJSON } from '../../../infrastructure/fetch-json' import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context' import { useLayoutContext } from '../../../shared/context/layout-context' import useScopeValue from '../../../shared/hooks/use-scope-value' import { useTranslation } from 'react-i18next' 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' import { useFileTreeData } from '../../../shared/context/file-tree-data-context' import useScopeEventListener from '../../../shared/hooks/use-scope-event-listener' import * as eventTracking from '../../../infrastructure/event-tracking' import { debugConsole } from '@/utils/debugging' import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path' import OLTooltip from '@/features/ui/components/ol/ol-tooltip' import OLButton from '@/features/ui/components/ol/ol-button' import MaterialIcon from '@/shared/components/material-icon' import { Spinner } from 'react-bootstrap-5' import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-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 { Placement } from 'react-bootstrap-5/types' const GoToCodeButton = memo(function GoToCodeButton({ syncToCode, syncToCodeInFlight, isDetachLayout, }: { syncToCode: ({ visualOffset }: { visualOffset: number }) => void syncToCodeInFlight: boolean isDetachLayout?: boolean }) { const { t } = useTranslation() const buttonClasses = classNames('synctex-control', { 'detach-synctex-control': !!isDetachLayout, }) let buttonIcon = null if (syncToCodeInFlight) { buttonIcon = (