From 7ab103edd9c3dbfa3c94b31167fc68487656a4d0 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Tue, 30 Jan 2024 22:03:47 +0800 Subject: [PATCH] feat: paste original elements by api --- src/editor/core/event/handlers/paste.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/editor/core/event/handlers/paste.ts b/src/editor/core/event/handlers/paste.ts index 6113957..24331ed 100644 --- a/src/editor/core/event/handlers/paste.ts +++ b/src/editor/core/event/handlers/paste.ts @@ -157,10 +157,18 @@ export async function pasteByApi(host: CanvasEvent, options?: IPasteOption) { paste() return } + // 优先读取编辑器内部粘贴板数据 + const clipboardText = await navigator.clipboard.readText() + const editorClipboardData = getClipboardData() + if (clipboardText === editorClipboardData?.text) { + pasteElement(host, editorClipboardData.elementList) + return + } + removeClipboardData() + // 从内存粘贴板获取数据 if (options?.isPlainText) { - const text = await navigator.clipboard.readText() - if (text) { - host.input(text) + if (clipboardText) { + host.input(clipboardText) } } else { const clipboardData = await navigator.clipboard.read()