diff --git a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx index 8fa4505f8c..713332ea3b 100644 --- a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx @@ -428,7 +428,9 @@ export const EditorManagerProvider: FC = ({ children }) => { const done = (isNewDoc: boolean) => { window.dispatchEvent( - new CustomEvent('doc:after-opened', { detail: isNewDoc }) + new CustomEvent('doc:after-opened', { + detail: { isNewDoc, docId: doc._id }, + }) ) if (hasGotoLine(options)) { window.setTimeout(() => jumpToLine(options)) diff --git a/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx b/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx index a7441d6c64..9975b028b2 100644 --- a/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx @@ -23,6 +23,7 @@ import { debugConsole } from '@/utils/debugging' import { convertFileRefToBinaryFile } from '@/features/ide-react/util/file-view' import { sendMB } from '@/infrastructure/event-tracking' import { FileRef } from '../../../../../types/file-ref' +import useEventListener from '@/shared/hooks/use-event-listener' const FileTreeOpenContext = createContext< | { @@ -113,21 +114,19 @@ export const FileTreeOpenProvider: FC = ({ children }) => { [eventEmitter, openDocId, openDocWithId, rootDocId] ) - const openDocIdRef = useRef(null) - // Synchronize the file tree when openDoc or openDocId is called on the editor // manager context from elsewhere. If the file tree does change, it will // trigger the onSelect handler in this component, which will update the local // state. - useEffect(() => { - if (openDocId !== openDocIdRef.current) { - debugConsole.log(`openDocId changed to ${openDocId}`) - openDocIdRef.current = openDocId - if (openDocId !== null) { - selectEntity(openDocId) - } - } - }, [openDocId, selectEntity]) + useEventListener( + 'doc:after-opened', + useCallback( + (event: CustomEvent<{ docId: string }>) => { + selectEntity(event.detail.docId) + }, + [selectEntity] + ) + ) // Open a document once the file tree and project are ready const initialOpenDoneRef = useRef(false) diff --git a/services/web/frontend/js/features/ide-react/context/outline-context.tsx b/services/web/frontend/js/features/ide-react/context/outline-context.tsx index 791e368494..4711103859 100644 --- a/services/web/frontend/js/features/ide-react/context/outline-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/outline-context.tsx @@ -91,7 +91,7 @@ export const OutlineProvider: FC = ({ children }) => { useEventListener( 'doc:after-opened', useCallback(evt => { - if (evt.detail) { + if (evt.detail.isNewDoc) { setIgnoreNextCursorUpdate(true) } setBinaryFileOpened(false)