mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 11:53:40 -05: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:
parent
88e4da6e3d
commit
9e72d55ea6
2 changed files with 6 additions and 7 deletions
|
@ -6,16 +6,16 @@ import { findInTree } from '@/features/file-tree/util/find-in-tree'
|
||||||
export function useOpenFile() {
|
export function useOpenFile() {
|
||||||
const ide = useIdeContext()
|
const ide = useIdeContext()
|
||||||
|
|
||||||
const { fileTreeData, setSelectedEntities } = useFileTreeData()
|
const { fileTreeData } = useFileTreeData()
|
||||||
|
|
||||||
const openFileWithId = useCallback(
|
const openFileWithId = useCallback(
|
||||||
(id: string) => {
|
(id: string) => {
|
||||||
const result = findInTree(fileTreeData, id)
|
const result = findInTree(fileTreeData, id)
|
||||||
if (result?.type === 'fileRef') {
|
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
|
// 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'
|
import { findInTree } from '@/features/file-tree/util/find-in-tree'
|
||||||
|
|
||||||
export function useSelectFileTreeEntity() {
|
export function useSelectFileTreeEntity() {
|
||||||
const { fileTreeData, selectedEntities, setSelectedEntities } =
|
const { fileTreeData, selectedEntities } = useFileTreeData()
|
||||||
useFileTreeData()
|
|
||||||
|
|
||||||
const selectEntity = useCallback(
|
const selectEntity = useCallback(
|
||||||
id => {
|
id => {
|
||||||
|
@ -16,10 +15,10 @@ export function useSelectFileTreeEntity() {
|
||||||
}
|
}
|
||||||
const entityToSelect = findInTree(fileTreeData, id)
|
const entityToSelect = findInTree(fileTreeData, id)
|
||||||
if (entityToSelect) {
|
if (entityToSelect) {
|
||||||
setSelectedEntities([entityToSelect])
|
window.dispatchEvent(new CustomEvent('editor.openDoc', { detail: id }))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[fileTreeData, selectedEntities, setSelectedEntities]
|
[fileTreeData, selectedEntities]
|
||||||
)
|
)
|
||||||
|
|
||||||
return { selectEntity }
|
return { selectEntity }
|
||||||
|
|
Loading…
Reference in a new issue