From 00ac804dd867d214c455292397206233fc784157 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Tue, 9 Mar 2021 11:52:28 +0530 Subject: [PATCH] fix: Allow copy of excalidraw elements only when inside excalidraw (#3206) * fix: Allow copy event only inside canvas * use pointerdown * use document.getSelection * remove poiterdown * remove keyTest * update changelog --- src/actions/actionClipboard.tsx | 2 +- src/components/App.tsx | 7 +++++++ src/keys.ts | 1 + src/packages/excalidraw/CHANGELOG.md | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/actions/actionClipboard.tsx b/src/actions/actionClipboard.tsx index fdbe41dc7..050fe3a26 100644 --- a/src/actions/actionClipboard.tsx +++ b/src/actions/actionClipboard.tsx @@ -17,7 +17,7 @@ export const actionCopy = register({ }; }, contextItemLabel: "labels.copy", - keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.C, + // Don't assign keyTest since its handled via copy event }); export const actionCut = register({ diff --git a/src/components/App.tsx b/src/components/App.tsx index 96a4191aa..95e577778 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1028,6 +1028,13 @@ class App extends React.Component { }); private onCopy = withBatchedUpdates((event: ClipboardEvent) => { + const activeSelection = document.getSelection(); + if ( + activeSelection?.anchorNode && + !this.excalidrawContainerRef.current!.contains(activeSelection.anchorNode) + ) { + return; + } if (isWritableElement(event.target)) { return; } diff --git a/src/keys.ts b/src/keys.ts index 31baff550..d8dff5654 100644 --- a/src/keys.ts +++ b/src/keys.ts @@ -40,6 +40,7 @@ export const KEYS = { TAB: "Tab", A: "a", + C: "c", D: "d", E: "e", L: "l", diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md index 7b3b4b587..1f2f2dfb3 100644 --- a/src/packages/excalidraw/CHANGELOG.md +++ b/src/packages/excalidraw/CHANGELOG.md @@ -18,6 +18,7 @@ Please add the latest change on the top under the correct section. ### Fixes +- Allow copy of excalidraw elements only when inside excalidraw [#3206](https://github.com/excalidraw/excalidraw/pull/3206). - Position text editor absolute and fix the offsets so it doesn't remain fixed when the container is scrolled [#3200](https://github.com/excalidraw/excalidraw/pull/3200). - Scope CSS variables so that host CSS vars don't clash with excalidraw [#3199](https://github.com/excalidraw/excalidraw/pull/3199).