mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #15792 from overleaf/td-ide-page-select-in-file-tree
Make selecting a file update the file tree reliably in React IDE page GitOrigin-RevId: a59ccc53371ee22d577b0de70abad4ffbe7f5398
This commit is contained in:
@@ -6,16 +6,16 @@ import { findInTree } from '@/features/file-tree/util/find-in-tree'
|
||||
export function useOpenFile() {
|
||||
const ide = useIdeContext()
|
||||
|
||||
const { fileTreeData, setSelectedEntities } = useFileTreeData()
|
||||
const { fileTreeData } = useFileTreeData()
|
||||
|
||||
const openFileWithId = useCallback(
|
||||
(id: string) => {
|
||||
const result = findInTree(fileTreeData, id)
|
||||
if (result?.type === 'fileRef') {
|
||||
setSelectedEntities(result)
|
||||
window.dispatchEvent(new CustomEvent('editor.openDoc', { detail: id }))
|
||||
}
|
||||
},
|
||||
[fileTreeData, setSelectedEntities]
|
||||
[fileTreeData]
|
||||
)
|
||||
|
||||
// Expose BinaryFilesManager via ide object solely for the benefit of the file
|
||||
|
||||
@@ -3,8 +3,7 @@ import { useCallback } from 'react'
|
||||
import { findInTree } from '@/features/file-tree/util/find-in-tree'
|
||||
|
||||
export function useSelectFileTreeEntity() {
|
||||
const { fileTreeData, selectedEntities, setSelectedEntities } =
|
||||
useFileTreeData()
|
||||
const { fileTreeData, selectedEntities } = useFileTreeData()
|
||||
|
||||
const selectEntity = useCallback(
|
||||
id => {
|
||||
@@ -16,10 +15,10 @@ export function useSelectFileTreeEntity() {
|
||||
}
|
||||
const entityToSelect = findInTree(fileTreeData, id)
|
||||
if (entityToSelect) {
|
||||
setSelectedEntities([entityToSelect])
|
||||
window.dispatchEvent(new CustomEvent('editor.openDoc', { detail: id }))
|
||||
}
|
||||
},
|
||||
[fileTreeData, selectedEntities, setSelectedEntities]
|
||||
[fileTreeData, selectedEntities]
|
||||
)
|
||||
|
||||
return { selectEntity }
|
||||
|
||||
Reference in New Issue
Block a user