mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Avoid changing the view when selecting a folder (#15315)
GitOrigin-RevId: 272c6f87507c65581041150905406f5c38e490d4
This commit is contained in:
parent
774a0a3f18
commit
0572535a7e
3 changed files with 37 additions and 5 deletions
|
@ -11,7 +11,7 @@ import classnames from 'classnames'
|
|||
function FileTreeDoc({ name, id, isFile, isLinkedFile }) {
|
||||
const { isSelected, props: selectableEntityProps } = useSelectableEntity(
|
||||
id,
|
||||
isFile
|
||||
isFile ? 'file' : 'doc'
|
||||
)
|
||||
|
||||
return (
|
||||
|
|
|
@ -17,7 +17,10 @@ import usePersistedState from '../../../shared/hooks/use-persisted-state'
|
|||
function FileTreeFolder({ name, id, folders, docs, files }) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { isSelected, props: selectableEntityProps } = useSelectableEntity(id)
|
||||
const { isSelected, props: selectableEntityProps } = useSelectableEntity(
|
||||
id,
|
||||
'folder'
|
||||
)
|
||||
|
||||
const { selectedEntityParentIds } = useFileTreeSelectable(id)
|
||||
|
||||
|
|
|
@ -210,9 +210,10 @@ const editorContextPropTypes = {
|
|||
|
||||
const isMac = /Mac/.test(window.navigator?.platform)
|
||||
|
||||
export function useSelectableEntity(id, isFile) {
|
||||
export function useSelectableEntity(id, type) {
|
||||
const { view, setView } = useLayoutContext()
|
||||
const { setContextMenuCoords } = useFileTreeMainContext()
|
||||
const { fileTreeData } = useFileTreeData()
|
||||
const {
|
||||
selectedEntityIds,
|
||||
selectOrMultiSelectEntity,
|
||||
|
@ -222,6 +223,26 @@ export function useSelectableEntity(id, isFile) {
|
|||
|
||||
const isSelected = selectedEntityIds.has(id)
|
||||
|
||||
const chooseView = useCallback(() => {
|
||||
for (const id of selectedEntityIds) {
|
||||
const selectedEntity = findInTree(fileTreeData, id)
|
||||
|
||||
if (selectedEntity.type === 'doc') {
|
||||
return 'editor'
|
||||
}
|
||||
|
||||
if (selectedEntity.type === 'fileRef') {
|
||||
return 'file'
|
||||
}
|
||||
|
||||
if (selectedEntity.type === 'folder') {
|
||||
return view
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}, [fileTreeData, selectedEntityIds, view])
|
||||
|
||||
const handleEvent = useCallback(
|
||||
ev => {
|
||||
ev.stopPropagation()
|
||||
|
@ -231,7 +252,14 @@ export function useSelectableEntity(id, isFile) {
|
|||
!isRootFolderSelected && (isMac ? ev.metaKey : ev.ctrlKey)
|
||||
setIsRootFolderSelected(false)
|
||||
selectOrMultiSelectEntity(id, multiSelect)
|
||||
setView(isFile ? 'file' : 'editor')
|
||||
|
||||
if (type === 'file') {
|
||||
setView('file')
|
||||
} else if (type === 'doc') {
|
||||
setView('editor')
|
||||
} else if (type === 'folder') {
|
||||
setView(chooseView())
|
||||
}
|
||||
},
|
||||
[
|
||||
id,
|
||||
|
@ -239,7 +267,8 @@ export function useSelectableEntity(id, isFile) {
|
|||
setIsRootFolderSelected,
|
||||
selectOrMultiSelectEntity,
|
||||
setView,
|
||||
isFile,
|
||||
type,
|
||||
chooseView,
|
||||
]
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue