From 7a566e4e6d05013fa802b30046dce3dacf97bbc3 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sun, 27 Oct 2024 11:27:29 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/12917 --- app/src/protyle/util/paste.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 1b4eab297..22921db49 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -221,6 +221,31 @@ export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Ele scrollCenter(protyle, undefined, false, "smooth"); }; +const readLocalFile = async (protyle: IProtyle, localFiles: string[]) => { + if (protyle && protyle.app && protyle.app.plugins) { + for (let i = 0; i < protyle.app.plugins.length; i++) { + const response: { files: string[] } = await new Promise((resolve) => { + const emitResult = protyle.app.plugins[i].eventBus.emit("paste", { + protyle, + resolve, + textHTML: "", + textPlain: "", + siyuanHTML: "", + files: localFiles + }); + if (emitResult) { + resolve(undefined); + } + }); + if (response?.files) { + localFiles = response.files; + } + } + } + uploadLocalFiles(localFiles, protyle, true); + writeText(""); +} + export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvent) & { target: HTMLElement }) => { event.stopPropagation(); event.preventDefault(); @@ -257,15 +282,13 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven localFiles.push(item.childNodes[0].nodeValue); }); if (localFiles.length > 0) { - uploadLocalFiles(localFiles, protyle, true); - writeText(""); + readLocalFile(protyle, localFiles); return; } } else { const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {}); if (xmlString.data.length > 0) { - uploadLocalFiles(xmlString.data, protyle, true); - writeText(""); + readLocalFile(protyle, xmlString.data); return; } }