mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-22 06:07:59 +00:00
Merge pull request #23710 from overleaf/dp-remove-file-tree-workaround
Remove pre-filetree work around for new editor GitOrigin-RevId: 7b34e4e298324ad217b603b48abbfbfa78d21804
This commit is contained in:
parent
2d02111e06
commit
3a9587797d
1 changed files with 0 additions and 37 deletions
|
@ -7,46 +7,9 @@ import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-o
|
|||
import useScopeValue from '@/shared/hooks/use-scope-value'
|
||||
import classNames from 'classnames'
|
||||
import SourceEditor from '@/features/source-editor/components/source-editor'
|
||||
import { useProjectContext } from '@/shared/context/project-context'
|
||||
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { findInTree } from '@/features/file-tree/util/find-in-tree'
|
||||
|
||||
// FIXME: This is only needed until we have a working file tree. This hook does
|
||||
// the minimal amount of work to load the initial document.
|
||||
const useWorkaroundForOpeningInitialDocument = () => {
|
||||
const { _id: projectId } = useProjectContext()
|
||||
const { fileTreeData, setSelectedEntities } = useFileTreeData()
|
||||
const isReady = Boolean(projectId && fileTreeData)
|
||||
const { handleFileTreeInit, handleFileTreeSelect } = useFileTreeOpenContext()
|
||||
const { currentDocumentId } = useEditorManagerContext()
|
||||
|
||||
useEffect(() => {
|
||||
if (isReady) handleFileTreeInit()
|
||||
}, [isReady, handleFileTreeInit])
|
||||
|
||||
const alreadyOpenedFile = useRef(false)
|
||||
useEffect(() => {
|
||||
if (isReady && currentDocumentId && !alreadyOpenedFile.current) {
|
||||
alreadyOpenedFile.current = true
|
||||
const doc = findInTree(fileTreeData, currentDocumentId)
|
||||
if (doc) {
|
||||
handleFileTreeSelect([doc])
|
||||
setSelectedEntities([doc])
|
||||
}
|
||||
}
|
||||
}, [
|
||||
isReady,
|
||||
currentDocumentId,
|
||||
fileTreeData,
|
||||
handleFileTreeSelect,
|
||||
setSelectedEntities,
|
||||
])
|
||||
}
|
||||
|
||||
export const Editor = () => {
|
||||
const [editor] = useScopeValue<EditorScopeValue>('editor')
|
||||
useWorkaroundForOpeningInitialDocument()
|
||||
const { selectedEntityCount, openEntity } = useFileTreeOpenContext()
|
||||
const { currentDocumentId } = useEditorManagerContext()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue