From 13e03fafa2741255a89842df48ccaec48c141747 Mon Sep 17 00:00:00 2001 From: Malik Glossop Date: Wed, 18 Feb 2026 13:02:56 +0100 Subject: [PATCH] Merge pull request #31591 from overleaf/mg-show-pdf-sync Always show pdf when jump to pdf menu item clicked GitOrigin-RevId: 4094e681c00d3acfed0f6072f428a6c83bb701c3 --- .../hooks/use-context-menu-items.tsx | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/hooks/use-context-menu-items.tsx b/services/web/frontend/js/features/source-editor/hooks/use-context-menu-items.tsx index 64ff557ea9..1a8573d950 100644 --- a/services/web/frontend/js/features/source-editor/hooks/use-context-menu-items.tsx +++ b/services/web/frontend/js/features/source-editor/hooks/use-context-menu-items.tsx @@ -34,7 +34,12 @@ export const useContextMenuItems = () => { const { wantTrackChanges } = useEditorPropertiesContext() const { syncToPdf, syncToPdfInFlight, canSyncToPdf } = useSynctex() const { pdfUrl, pdfViewer } = useDetachCompileContext() - const { detachRole } = useLayoutContext() + const { + detachRole, + changeLayout, + pdfLayout, + view: ideView, + } = useLayoutContext() const visualPreviewEnabled = useFeatureFlag('visual-preview') const { t } = useTranslation() const { shortcuts } = useCommandRegistry() @@ -72,12 +77,14 @@ export const useContextMenuItems = () => { const hasSelection = !state.selection.main.empty const canEdit = permissions.write || permissions.trackedWrite + + // Determine layout states for PDF sync functionality + const isPdfDetached = detachRole === 'detacher' + const isEditorOnly = + pdfLayout === 'flat' && ideView === 'editor' && !isPdfDetached + const jumpToLocationInPdfEnabled = - pdfUrl && - pdfViewer !== 'native' && - !detachRole && - !visualPreviewEnabled && - canSyncToPdf + pdfUrl && pdfViewer !== 'native' && !visualPreviewEnabled && canSyncToPdf const wrapForContextMenu = useCallback( (command: () => Promise | boolean) => async () => { @@ -119,10 +126,14 @@ export const useContextMenuItems = () => { // Sync-to-PDF is special: it needs to wait for async completion before closing const handleSyncToPdf = useCallback(() => { + // Switch to split view only when in editor-only mode with non-detached PDF + if (isEditorOnly) { + changeLayout('sideBySide') + } requestedPdfSyncRef.current = true syncToPdf() view.focus() - }, [syncToPdf, view]) + }, [syncToPdf, view, changeLayout, isEditorOnly]) const getShortcut = useCallback( (id: string) => {