From debae2326ec265857c07468e1b470ed4ea273019 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 20 Nov 2023 12:35:19 +0100 Subject: [PATCH] fix(editor): don't create empty "blob" files when pasting images --- src/components/input/editor/TipTap.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/input/editor/TipTap.vue b/src/components/input/editor/TipTap.vue index 07d4a0aca0..dd61ec7db4 100644 --- a/src/components/input/editor/TipTap.vue +++ b/src/components/input/editor/TipTap.vue @@ -507,12 +507,16 @@ onBeforeUnmount(() => { }) function handleImagePaste(event) { + if (event?.clipboardData?.items?.length === 0) { + return + } + event.preventDefault() - event?.clipboardData?.items?.forEach(i => { - if (i.kind === 'file' && i.type.startsWith('image/')) { - uploadAndInsertFiles([i.getAsFile()]) - } - }) + + const image = event.clipboardData.items[0] + if (image.kind === 'file' && image.type.startsWith('image/')) { + uploadAndInsertFiles([image.getAsFile()]) + } } // See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660