diff --git a/ts/routes/editor/NoteEditor.svelte b/ts/routes/editor/NoteEditor.svelte index 861c0109f..8a0dae384 100644 --- a/ts/routes/editor/NoteEditor.svelte +++ b/ts/routes/editor/NoteEditor.svelte @@ -32,6 +32,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html openFilePickerForImageOcclusion, readImageFromClipboard, extractImagePathFromHtml, + extractImagePathFromData, } from "./rich-text-input/data-transfer"; import contextProperty from "$lib/sveltelib/context-property"; import lifecycleHooks from "$lib/sveltelib/lifecycle-hooks"; @@ -601,6 +602,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html await setupMaskEditorFromClipboard(); } + async function handlePickerDrop(event: DragEvent) { + if($editorState === EditorState.ImageOcclusionPicker) { + const path = await extractImagePathFromData(event.dataTransfer!); + if (path) { + setupMaskEditor(path); + event.preventDefault(); + } + } + } + async function setupMaskEditor(filename: string) { if (mode == "add") { setupMaskEditorForNewNote(filename); @@ -999,6 +1010,8 @@ components and functionality for general note editing. on:contextmenu={(event) => { onContextMenu(event, api, $focusedInput, contextMenu); }} + on:dragover|preventDefault + on:drop={handlePickerDrop} > diff --git a/ts/routes/editor/rich-text-input/data-transfer.ts b/ts/routes/editor/rich-text-input/data-transfer.ts index 4d00688f9..b941ff932 100644 --- a/ts/routes/editor/rich-text-input/data-transfer.ts +++ b/ts/routes/editor/rich-text-input/data-transfer.ts @@ -248,7 +248,6 @@ async function processUrls( url = lines[0]; text += await urlToLink(url, allowedSuffixes); } - return text; } @@ -421,15 +420,18 @@ export async function extractImagePathFromHtml(html: string): Promise { + const html = await processUrls(data, Promise.resolve(false), imageSuffixes); + if (html) { + return await extractImagePathFromHtml(html); + } + return null; +} export async function readImageFromClipboard(): Promise { // TODO: check browser support and available formats for (const item of await navigator.clipboard.read()) { - let path: string | null = null; - const html = await processUrls(item, Promise.resolve(false), imageSuffixes); - if (html) { - path = await extractImagePathFromHtml(html); - } + let path = await extractImagePathFromData(item); if (!path) { const image = await getImageData(item); if (!image) {