Call selectEntity directly after a doc is opened (#18329)

GitOrigin-RevId: bf471812bfeb5e394252733a16691430d7d45840
This commit is contained in:
Alf Eaton 2024-05-16 09:29:58 +01:00 committed by Copybot
parent e8a5f8f056
commit c8947c781e
3 changed files with 14 additions and 13 deletions

View file

@ -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))

View file

@ -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<typeof openDocId | null>(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)

View file

@ -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)