From 82be39881ecc25dbf98992dc713e5b617f000fee Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 25 Apr 2022 12:10:55 +0200 Subject: Fix drag&drop of non-image objects Only catch drop with custom image-drop event if it contains files. Fixes: #2317 Signed-off-by: Jonas Signed-off-by: nextcloud-command --- src/nodes/Image.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nodes/Image.js b/src/nodes/Image.js index 11a05532a..6a1a250cf 100644 --- a/src/nodes/Image.js +++ b/src/nodes/Image.js @@ -45,19 +45,22 @@ const Image = TiptapImage.extend({ new Plugin({ props: { handleDrop: (view, event, slice) => { - const coordinates = view.posAtCoords({ left: event.clientX, top: event.clientY }) - const customEvent = new CustomEvent('image-drop', { - bubbles: true, - detail: { - files: event.dataTransfer.files, - position: coordinates.pos, - }, - }) - event.target.dispatchEvent(customEvent) - return true + // only catch the drop if it contains files + if (event.dataTransfer.files && event.dataTransfer.files.length > 0) { + const coordinates = view.posAtCoords({ left: event.clientX, top: event.clientY }) + const customEvent = new CustomEvent('image-drop', { + bubbles: true, + detail: { + files: event.dataTransfer.files, + position: coordinates.pos, + }, + }) + event.target.dispatchEvent(customEvent) + return true + } }, handlePaste: (view, event, slice) => { - // only prevent the paste if it contains files + // only catch the paste if it contains files if (event.clipboardData.files && event.clipboardData.files.length > 0) { // let the editor wrapper catch this custom event const customEvent = new CustomEvent('image-paste', { -- cgit v1.2.3