diff --git a/services/web/frontend/js/features/file-tree/components/file-tree-doc.jsx b/services/web/frontend/js/features/file-tree/components/file-tree-doc.jsx
index da4e13ba9e..1285f8513b 100644
--- a/services/web/frontend/js/features/file-tree/components/file-tree-doc.jsx
+++ b/services/web/frontend/js/features/file-tree/components/file-tree-doc.jsx
@@ -9,9 +9,11 @@ import iconTypeFromName from '../util/icon-type-from-name'
import classnames from 'classnames'
function FileTreeDoc({ name, id, isFile, isLinkedFile }) {
+ const type = isFile ? 'file' : 'doc'
+
const { isSelected, props: selectableEntityProps } = useSelectableEntity(
id,
- isFile ? 'file' : 'doc'
+ type
)
return (
@@ -26,6 +28,7 @@ function FileTreeDoc({ name, id, isFile, isLinkedFile }) {
}
/>
diff --git a/services/web/frontend/js/features/file-tree/components/file-tree-folder.jsx b/services/web/frontend/js/features/file-tree/components/file-tree-folder.jsx
index e6d2d417c7..07301c5142 100644
--- a/services/web/frontend/js/features/file-tree/components/file-tree-folder.jsx
+++ b/services/web/frontend/js/features/file-tree/components/file-tree-folder.jsx
@@ -80,6 +80,7 @@ function FileTreeFolder({ name, id, folders, docs, files }) {
diff --git a/services/web/frontend/js/features/file-tree/components/file-tree-item/file-tree-item-inner.tsx b/services/web/frontend/js/features/file-tree/components/file-tree-item/file-tree-item-inner.tsx
index ebee24ef92..75d2bf4216 100644
--- a/services/web/frontend/js/features/file-tree/components/file-tree-item/file-tree-item-inner.tsx
+++ b/services/web/frontend/js/features/file-tree/components/file-tree-item/file-tree-item-inner.tsx
@@ -15,11 +15,13 @@ import { useDragDropManager } from 'react-dnd'
function FileTreeItemInner({
id,
name,
+ type,
isSelected,
icons,
}: {
id: string
name: string
+ type: string
isSelected: boolean
icons?: ReactNode
}) {
@@ -76,6 +78,8 @@ function FileTreeItemInner({
ref={dragRef}
draggable={!isRenaming}
onContextMenu={handleContextMenu}
+ data-file-id={id}
+ data-file-type={type}
>
void
@@ -43,6 +44,41 @@ const FileTreeRoot = React.memo<{
const { fileTreeData } = useFileTreeData()
const isReady = Boolean(projectId && fileTreeData)
+ useEffect(() => {
+ if (fileTreeContainer) {
+ const listener = (event: DragEvent) => {
+ if (event.dataTransfer) {
+ // store the dragged entity in dataTransfer
+ const { dataset } = event.target as HTMLDivElement
+ if (
+ dataset.fileId &&
+ dataset.fileType &&
+ dataset.fileType !== 'folder'
+ ) {
+ event.dataTransfer.setData(
+ 'application/x-overleaf-file-id',
+ dataset.fileId
+ )
+
+ const filePath = pathInFolder(fileTreeData, dataset.fileId)
+ if (filePath) {
+ event.dataTransfer.setData(
+ 'application/x-overleaf-file-path',
+ filePath
+ )
+ }
+ }
+ }
+ }
+
+ fileTreeContainer.addEventListener('dragstart', listener)
+
+ return () => {
+ fileTreeContainer.removeEventListener('dragstart', listener)
+ }
+ }
+ }, [fileTreeContainer, fileTreeData])
+
useEffect(() => {
if (isReady) onInit()
}, [isReady, onInit])
diff --git a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-context.tsx b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-context.tsx
index e5c93ea888..db4bce4c90 100644
--- a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-context.tsx
+++ b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-context.tsx
@@ -22,6 +22,7 @@ type FigureModalState = {
includeLabel: boolean
error?: string
pastedImageData?: PastedImageData
+ selectedItemId?: string
}
type FigureModalStateUpdate = Partial
diff --git a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal.tsx b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal.tsx
index 0b0674d823..cac28f2a52 100644
--- a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal.tsx
+++ b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal.tsx
@@ -70,8 +70,16 @@ const FigureModalContent = () => {
const listener = useCallback(
(event: Event) => {
- const { detail: source } = event as CustomEvent
- dispatch({ source })
+ const { detail } = event as CustomEvent<{
+ source: FigureModalSource
+ fileId?: string
+ filePath?: string
+ }>
+ dispatch({
+ source: detail.source,
+ selectedItemId: detail.fileId,
+ getPath: detail.filePath ? async () => detail.filePath! : undefined,
+ })
},
[dispatch]
)
diff --git a/services/web/frontend/js/features/source-editor/components/figure-modal/file-sources/figure-modal-project-source.tsx b/services/web/frontend/js/features/source-editor/components/figure-modal/file-sources/figure-modal-project-source.tsx
index 10dba3131d..4846af85f8 100644
--- a/services/web/frontend/js/features/source-editor/components/figure-modal/file-sources/figure-modal-project-source.tsx
+++ b/services/web/frontend/js/features/source-editor/components/figure-modal/file-sources/figure-modal-project-source.tsx
@@ -12,7 +12,7 @@ export const FigureModalCurrentProjectSource: FC = () => {
() => filterFiles(rootFolder)?.filter(isImageFile),
[rootFolder]
)
- const { dispatch } = useFigureModalContext()
+ const { dispatch, selectedItemId } = useFigureModalContext()
const noFiles = files?.length === 0
return (