diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-logs-entries.js b/services/web/frontend/js/features/pdf-preview/components/pdf-logs-entries.js index a4352c49ab..57ef298b30 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-logs-entries.js +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-logs-entries.js @@ -1,39 +1,15 @@ -import { memo, useCallback } from 'react' +import { memo } from 'react' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' import PreviewLogsPaneMaxEntries from '../../preview/components/preview-logs-pane-max-entries' import PdfLogEntry from './pdf-log-entry' -import { useIdeContext } from '../../../shared/context/ide-context' -import useDetachAction from '../../../shared/hooks/use-detach-action' +import { useDetachCompileContext } from '../../../shared/context/detach-compile-context' const LOG_PREVIEW_LIMIT = 100 function PdfLogsEntries({ entries, hasErrors }) { const { t } = useTranslation() - - const ide = useIdeContext() - - const _syncToEntry = useCallback( - entry => { - const entity = ide.fileTreeManager.findEntityByPath(entry.file) - - if (entity && entity.type === 'doc') { - ide.editorManager.openDoc(entity, { - gotoLine: entry.line ?? undefined, - gotoColumn: entry.column ?? undefined, - }) - } - }, - [ide] - ) - - const syncToEntry = useDetachAction( - 'sync-to-entry', - _syncToEntry, - 'detached', - 'detacher' - ) - + const { syncToEntry } = useDetachCompileContext() const logEntries = entries.slice(0, LOG_PREVIEW_LIMIT) return ( diff --git a/services/web/frontend/js/shared/context/detach-compile-context.js b/services/web/frontend/js/shared/context/detach-compile-context.js index 01e37576de..14491a826f 100644 --- a/services/web/frontend/js/shared/context/detach-compile-context.js +++ b/services/web/frontend/js/shared/context/detach-compile-context.js @@ -72,6 +72,7 @@ export function DetachCompileProvider({ children }) { setChangedAt: _setChangedAt, setSavedAt: _setSavedAt, clearCache: _clearCache, + syncToEntry: _syncToEntry, } = localCompileContext const [animateCompileDropdownArrow] = useDetachStateWatcher( @@ -366,6 +367,13 @@ export function DetachCompileProvider({ children }) { 'detacher' ) + const syncToEntry = useDetachAction( + 'sync-to-entry', + _syncToEntry, + 'detached', + 'detacher' + ) + useCompileTriggers(startCompile, setChangedAt, setSavedAt) useEffect(() => { // Sync the split test variant across the editor and pdf-detach. @@ -426,6 +434,7 @@ export function DetachCompileProvider({ children }) { firstRenderDone, setChangedAt, cleanupCompileResult, + syncToEntry, }), [ animateCompileDropdownArrow, @@ -477,6 +486,7 @@ export function DetachCompileProvider({ children }) { firstRenderDone, setChangedAt, cleanupCompileResult, + syncToEntry, ] ) diff --git a/services/web/frontend/js/shared/context/local-compile-context.js b/services/web/frontend/js/shared/context/local-compile-context.js index 312ce14bba..14db362f5d 100644 --- a/services/web/frontend/js/shared/context/local-compile-context.js +++ b/services/web/frontend/js/shared/context/local-compile-context.js @@ -522,6 +522,20 @@ export function LocalCompileProvider({ children }) { }) }, [compiler]) + const syncToEntry = useCallback( + entry => { + const entity = ide.fileTreeManager.findEntityByPath(entry.file) + + if (entity && entity.type === 'doc') { + ide.editorManager.openDoc(entity, { + gotoLine: entry.line ?? undefined, + gotoColumn: entry.column ?? undefined, + }) + } + }, + [ide] + ) + // clear the cache then run a compile, triggered by a menu item const recompileFromScratch = useCallback(() => { clearCache().then(() => { @@ -587,6 +601,7 @@ export function LocalCompileProvider({ children }) { setChangedAt, setSavedAt, cleanupCompileResult, + syncToEntry, }), [ animateCompileDropdownArrow, @@ -638,6 +653,7 @@ export function LocalCompileProvider({ children }) { cleanupCompileResult, setShowLogs, toggleLogs, + syncToEntry, ] )