diff --git a/src/clipboard.test.ts b/src/clipboard.test.ts new file mode 100644 index 00000000..142038e8 --- /dev/null +++ b/src/clipboard.test.ts @@ -0,0 +1,27 @@ +import { parseClipboard } from "./clipboard"; + +describe("Test parseClipboard", () => { + it("should parse valid json correctly", async () => { + let text = "123"; + + let clipboardData = await parseClipboard({ + //@ts-ignore + clipboardData: { + getData: () => text, + }, + }); + + expect(clipboardData.text).toBe(text); + + text = "[123]"; + + clipboardData = await parseClipboard({ + //@ts-ignore + clipboardData: { + getData: () => text, + }, + }); + + expect(clipboardData.text).toBe(text); + }); +}); diff --git a/src/clipboard.ts b/src/clipboard.ts index bc4d3d3b..4e2c0622 100644 --- a/src/clipboard.ts +++ b/src/clipboard.ts @@ -156,15 +156,13 @@ export const parseClipboard = async ( files: systemClipboardData.files, }; } - return appClipboardData; - } catch { - // system clipboard doesn't contain excalidraw elements → return plaintext - // unless we set a flag to prefer in-app clipboard because browser didn't - // support storing to system clipboard on copy - return PREFER_APP_CLIPBOARD && appClipboardData.elements - ? appClipboardData - : { text: systemClipboard }; - } + } catch (e) {} + // system clipboard doesn't contain excalidraw elements → return plaintext + // unless we set a flag to prefer in-app clipboard because browser didn't + // support storing to system clipboard on copy + return PREFER_APP_CLIPBOARD && appClipboardData.elements + ? appClipboardData + : { text: systemClipboard }; }; export const copyBlobToClipboardAsPng = async (blob: Blob | Promise) => {