From cc762bb7e653b07c9d5dd4450de0c28be1d478d2 Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen Date: Tue, 2 Jun 2026 13:10:45 +0100 Subject: [PATCH] Merge pull request #33994 from overleaf/mj-command-palette-synctex [web] Add synctex to command palette GitOrigin-RevId: 10e769dae6088d279d010fcfa3577b489c6ff89c --- .../hooks/use-command-registry-source.tsx | 2 + .../components/pdf-synctex-controls.tsx | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/services/web/frontend/js/features/command-palette/hooks/use-command-registry-source.tsx b/services/web/frontend/js/features/command-palette/hooks/use-command-registry-source.tsx index 4744681442..3ce5dcefd8 100644 --- a/services/web/frontend/js/features/command-palette/hooks/use-command-registry-source.tsx +++ b/services/web/frontend/js/features/command-palette/hooks/use-command-registry-source.tsx @@ -18,6 +18,8 @@ const ENABLED_COMMANDS: string[] = [ 'compile', 'stop-compile', 'recompile-from-scratch', + 'synctex-sync-to-pdf', + 'synctex-sync-to-code', ] const useCommandRegistrySource = (): CommandPaletteSource => { diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.tsx b/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.tsx index 75c840133a..63f7c14de8 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.tsx +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.tsx @@ -11,6 +11,7 @@ import useSynctex from '../hooks/use-synctex' import { useFeatureFlag } from '@/shared/context/split-test-context' import OLSpinner from '@/shared/components/ol/ol-spinner' import { sendMB } from '@/infrastructure/event-tracking' +import { useCommandProvider } from '@/features/ide-react/hooks/use-command-provider' const GoToCodeButton = memo(function GoToCodeButton({ syncToCode, @@ -22,6 +23,24 @@ const GoToCodeButton = memo(function GoToCodeButton({ isDetachLayout?: boolean }) { const { t } = useTranslation() + useCommandProvider( + () => [ + { + id: 'synctex-sync-to-code', + handler: () => { + sendMB('jump-to-location', { + method: 'command', + direction: 'pdf-location-in-code', + }) + syncToCode({ visualOffset: 72 }) + }, + disabled: syncToCodeInFlight, + label: t('go_to_pdf_location_in_code'), + }, + ], + [t, syncToCode, syncToCodeInFlight] + ) + const buttonClasses = classNames('synctex-control', { 'detach-synctex-control': !!isDetachLayout, }) @@ -98,6 +117,24 @@ const GoToPdfButton = memo(function GoToPdfButton({ syncToPdf() }, [syncToPdf]) + useCommandProvider( + () => [ + { + id: 'synctex-sync-to-pdf', + handler: () => { + sendMB('jump-to-location', { + method: 'command', + direction: 'code-location-in-pdf', + }) + syncToPdf() + }, + label: t('go_to_code_location_in_pdf'), + disabled: syncToPdfInFlight || !canSyncToPdf, + }, + ], + [t, syncToPdf, syncToPdfInFlight, canSyncToPdf] + ) + let buttonIcon = null if (syncToPdfInFlight) { buttonIcon =