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) => {