mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Call selectEntity directly after a doc is opened (#18329)
GitOrigin-RevId: bf471812bfeb5e394252733a16691430d7d45840
This commit is contained in:
parent
e8a5f8f056
commit
c8947c781e
3 changed files with 14 additions and 13 deletions
|
@ -428,7 +428,9 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||||
|
|
||||||
const done = (isNewDoc: boolean) => {
|
const done = (isNewDoc: boolean) => {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent('doc:after-opened', { detail: isNewDoc })
|
new CustomEvent('doc:after-opened', {
|
||||||
|
detail: { isNewDoc, docId: doc._id },
|
||||||
|
})
|
||||||
)
|
)
|
||||||
if (hasGotoLine(options)) {
|
if (hasGotoLine(options)) {
|
||||||
window.setTimeout(() => jumpToLine(options))
|
window.setTimeout(() => jumpToLine(options))
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { debugConsole } from '@/utils/debugging'
|
||||||
import { convertFileRefToBinaryFile } from '@/features/ide-react/util/file-view'
|
import { convertFileRefToBinaryFile } from '@/features/ide-react/util/file-view'
|
||||||
import { sendMB } from '@/infrastructure/event-tracking'
|
import { sendMB } from '@/infrastructure/event-tracking'
|
||||||
import { FileRef } from '../../../../../types/file-ref'
|
import { FileRef } from '../../../../../types/file-ref'
|
||||||
|
import useEventListener from '@/shared/hooks/use-event-listener'
|
||||||
|
|
||||||
const FileTreeOpenContext = createContext<
|
const FileTreeOpenContext = createContext<
|
||||||
| {
|
| {
|
||||||
|
@ -113,21 +114,19 @@ export const FileTreeOpenProvider: FC = ({ children }) => {
|
||||||
[eventEmitter, openDocId, openDocWithId, rootDocId]
|
[eventEmitter, openDocId, openDocWithId, rootDocId]
|
||||||
)
|
)
|
||||||
|
|
||||||
const openDocIdRef = useRef<typeof openDocId | null>(null)
|
|
||||||
|
|
||||||
// Synchronize the file tree when openDoc or openDocId is called on the editor
|
// 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
|
// manager context from elsewhere. If the file tree does change, it will
|
||||||
// trigger the onSelect handler in this component, which will update the local
|
// trigger the onSelect handler in this component, which will update the local
|
||||||
// state.
|
// state.
|
||||||
useEffect(() => {
|
useEventListener(
|
||||||
if (openDocId !== openDocIdRef.current) {
|
'doc:after-opened',
|
||||||
debugConsole.log(`openDocId changed to ${openDocId}`)
|
useCallback(
|
||||||
openDocIdRef.current = openDocId
|
(event: CustomEvent<{ docId: string }>) => {
|
||||||
if (openDocId !== null) {
|
selectEntity(event.detail.docId)
|
||||||
selectEntity(openDocId)
|
},
|
||||||
}
|
[selectEntity]
|
||||||
}
|
)
|
||||||
}, [openDocId, selectEntity])
|
)
|
||||||
|
|
||||||
// Open a document once the file tree and project are ready
|
// Open a document once the file tree and project are ready
|
||||||
const initialOpenDoneRef = useRef(false)
|
const initialOpenDoneRef = useRef(false)
|
||||||
|
|
|
@ -91,7 +91,7 @@ export const OutlineProvider: FC = ({ children }) => {
|
||||||
useEventListener(
|
useEventListener(
|
||||||
'doc:after-opened',
|
'doc:after-opened',
|
||||||
useCallback(evt => {
|
useCallback(evt => {
|
||||||
if (evt.detail) {
|
if (evt.detail.isNewDoc) {
|
||||||
setIgnoreNextCursorUpdate(true)
|
setIgnoreNextCursorUpdate(true)
|
||||||
}
|
}
|
||||||
setBinaryFileOpened(false)
|
setBinaryFileOpened(false)
|
||||||
|
|
Loading…
Reference in a new issue