Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Preserve pasted files when plugins replace clipboard text https://github.com/siyuan-note/siyuan/issues/12429

Daniel78ecb8bbad81
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts
index 93ed9a1b19..20ad746740 100644
--- a/app/src/protyle/util/paste.ts
+++ b/app/src/protyle/util/paste.ts
@@ -581,8 +581,8 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
});
if (response) {
- // 插件返回的是完整的剪贴板载荷,未返回字段需清空,避免原数据影响后续处理
- const normalizedResponse = normalizePasteResponse(response);
+ // 插件返回的是完整的剪贴板文本载荷,文件字段仅在显式返回时替换
+ const normalizedResponse = normalizePasteResponse(response, files);
textHTML = normalizedResponse.textHTML;
textPlain = normalizedResponse.textPlain;
siyuanHTML = normalizedResponse.siyuanHTML;
diff --git a/app/src/protyle/util/pasteResponse.test.ts b/app/src/protyle/util/pasteResponse.test.ts
index 17d83a4a0a..4b677d6ac5 100644
--- a/app/src/protyle/util/pasteResponse.test.ts
+++ b/app/src/protyle/util/pasteResponse.test.ts
@@ -3,12 +3,13 @@ import * as assert from "node:assert/strict";
import {normalizePasteResponse} from "./pasteResponse";
describe("normalizePasteResponse", () => {
- it("clears clipboard formats omitted from a plugin response", () => {
- assert.deepEqual(normalizePasteResponse({textPlain: "updated"}), {
+ it("clears omitted text formats and preserves existing files", () => {
+ const files = [{} as File];
+ assert.deepEqual(normalizePasteResponse({textPlain: "updated"}, files), {
textHTML: "",
textPlain: "updated",
siyuanHTML: "",
- files: [],
+ files,
});
});
@@ -26,4 +27,14 @@ describe("normalizePasteResponse", () => {
files,
});
});
+
+ it("clears existing files when a plugin returns an empty file list", () => {
+ const files = [{} as File];
+ assert.deepEqual(normalizePasteResponse({textPlain: "updated", files: []}, files), {
+ textHTML: "",
+ textPlain: "updated",
+ siyuanHTML: "",
+ files: [],
+ });
+ });
});
diff --git a/app/src/protyle/util/pasteResponse.ts b/app/src/protyle/util/pasteResponse.ts
index 24a471f835..b00e581373 100644
--- a/app/src/protyle/util/pasteResponse.ts
+++ b/app/src/protyle/util/pasteResponse.ts
@@ -1,6 +1,6 @@
-export const normalizePasteResponse = (response: IClipboardData) => ({
+export const normalizePasteResponse = (response: IClipboardData, files: IClipboardData["files"] = []) => ({
textHTML: response.textHTML ?? "",
textPlain: response.textPlain ?? "",
siyuanHTML: response.siyuanHTML ?? "",
- files: response.files ?? [],
+ files: response.files ?? files,
});