From 57769e47b74e1c3d2e719dc8a0ecaf745f906830 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Fri, 13 May 2022 13:00:53 +0100 Subject: [PATCH] fix copy and paste on Safari (#680) --- packages/tldraw/src/state/TldrawApp.ts | 49 ++++++++++++++++---------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/packages/tldraw/src/state/TldrawApp.ts b/packages/tldraw/src/state/TldrawApp.ts index 88384490a..4f259ff6e 100644 --- a/packages/tldraw/src/state/TldrawApp.ts +++ b/packages/tldraw/src/state/TldrawApp.ts @@ -1753,6 +1753,8 @@ export class TldrawApp extends StateManager { * @param ids The ids of the shapes to cut. */ cut = (ids = this.selectedIds, pageId = this.currentPageId, e?: ClipboardEvent): this => { + e?.preventDefault() + this.copy(ids, pageId, e) if (!this.readOnly) { this.delete(ids) @@ -1765,6 +1767,8 @@ export class TldrawApp extends StateManager { * @param ids The ids of the shapes to copy. */ copy = (ids = this.selectedIds, pageId = this.currentPageId, e?: ClipboardEvent): this => { + e?.preventDefault() + this.clipboard = this.getClipboard(ids, pageId) const tldrawString = JSON.stringify({ @@ -1773,7 +1777,7 @@ export class TldrawApp extends StateManager { }) if (e) { - e.clipboardData?.setData('text/hmtl', tldrawString) + e.clipboardData?.setData('text/html', tldrawString) } if (navigator.clipboard) { @@ -1925,7 +1929,9 @@ export class TldrawApp extends StateManager { const pasteAsHTML = (html: string) => { try { - const maybeJson = html.slice(''.length) + const maybeJson = html.startsWith('<') ? html.match(/({".*})$| { // and tiling them out on the canvas. At the moment, let's just // support pasting one file / image. - switch (item.kind) { - case 'string': { - item.getAsString(async (text) => { - if (text.startsWith(' { + pasteAsHTML(text) + }) + return + } else { + switch (item.kind) { + case 'string': { + item.getAsString(async (text) => { + if (text.startsWith('