diff options
Diffstat (limited to 'apps/files/src/components/FileEntryMixin.ts')
-rw-r--r-- | apps/files/src/components/FileEntryMixin.ts | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/apps/files/src/components/FileEntryMixin.ts b/apps/files/src/components/FileEntryMixin.ts index e5d6a27e96c..7ad5229c933 100644 --- a/apps/files/src/components/FileEntryMixin.ts +++ b/apps/files/src/components/FileEntryMixin.ts @@ -18,9 +18,10 @@ import Vue, { defineComponent } from 'vue' import { action as sidebarAction } from '../actions/sidebarAction.ts' import { getDragAndDropPreview } from '../utils/dragUtils.ts' import { hashCode } from '../utils/hashUtils.ts' -import { dataTransferToFileTree, onDropExternalFiles, onDropInternalFiles } from '../services/DropService.ts' +import { onDropExternalFiles, onDropInternalFiles } from '../services/DropService.ts' import logger from '../logger.ts' import { isDownloadable } from '../utils/permissions.ts' +import { useLink } from 'vue-router/composables' Vue.directive('onClickOutside', vOnClickOutside) @@ -337,15 +338,15 @@ export default defineComponent({ onDragOver(event: DragEvent) { this.dragover = this.canDrop - if (!this.canDrop) { + if (!this.canDrop && event.dataTransfer) { event.dataTransfer.dropEffect = 'none' return } // Handle copy/move drag and drop - if (event.ctrlKey) { + if (event.ctrlKey && event.dataTransfer) { event.dataTransfer.dropEffect = 'copy' - } else { + } else if (event.dataTransfer) { event.dataTransfer.dropEffect = 'move' } }, @@ -405,40 +406,36 @@ export default defineComponent({ event.preventDefault() event.stopPropagation() + // If another button is pressed, cancel it. This + // allows cancelling the drag with the right click. + if (!this.canDrop || event.button) { + return + } + // Caching the selection const selection = this.draggingFiles const items = [...event.dataTransfer?.items || []] as DataTransferItem[] - // We need to process the dataTransfer ASAP before the - // browser clears it. This is why we cache the items too. - const fileTree = await dataTransferToFileTree(items) - - // We might not have the target directory fetched yet - const contents = await this.currentView?.getContents(this.source.path) - const folder = contents?.folder - if (!folder) { - showError(this.t('files', 'Target folder does not exist any more')) - return - } + logger.debug('Dropped', { event, selection }) - // If another button is pressed, cancel it. This - // allows cancelling the drag with the right click. - if (!this.canDrop || event.button) { + // Check whether we're uploading files + if (items.find((item) => item.kind === 'file') !== undefined) { + await onDropExternalFiles(items) + this.dragover = false return } - const isCopy = event.ctrlKey + // Else we are copying / moving files this.dragover = false - logger.debug('Dropped', { event, folder, selection, fileTree }) - - // Check whether we're uploading files - if (fileTree.contents.length > 0) { - await onDropExternalFiles(fileTree, folder, contents.contents) + const contents = await this.currentView?.getContents(this.source.path) + const folder = contents?.folder + if (!folder) { + showError(this.t('files', 'Target folder does not exist any more')) return } - // Else we're moving/copying files + const isCopy = event.ctrlKey const nodes = selection.map(source => this.filesStore.getNode(source)) as Node[] await onDropInternalFiles(nodes, folder, contents.contents, isCopy) |