From 0e3eb3cc634bcd8fe561579a42cc16c40f4eea9f Mon Sep 17 00:00:00 2001 From: Matias Capeletto Date: Thu, 18 Mar 2021 18:27:00 +0100 Subject: [PATCH 1/2] chore: fix npm to yarn in contributing.md and package.json (#3274) * chore: fix npm to yarn in contributing.md * chore: fix npm pack to yarn pack --- CONTRIBUTING.md | 2 +- src/packages/utils/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 611dc5c16..b3a5c325c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ ### Option 1 - Manual 1. Fork and clone the repo -1. Run `npm install` to install dependencies +1. Run `yarn` to install dependencies 1. Create a branch for your PR with `git checkout -b your-branch-name` > To keep `master` branch pointing to remote repository and make pull requests from branches on your fork. To do this, run: diff --git a/src/packages/utils/package.json b/src/packages/utils/package.json index 092463a61..b19e21aad 100644 --- a/src/packages/utils/package.json +++ b/src/packages/utils/package.json @@ -57,6 +57,6 @@ "scripts": { "build:umd": "cross-env NODE_ENV=production webpack --config webpack.prod.config.js", "build:umd:withAnalyzer": "cross-env NODE_ENV=production ANALYZER=true webpack --config webpack.prod.config.js", - "pack": "yarn build:umd && npm pack" + "pack": "yarn build:umd && yarn pack" } } From add1785ace677b1a156b523d246860b926b5382e Mon Sep 17 00:00:00 2001 From: David Luzar Date: Fri, 19 Mar 2021 18:36:23 +0100 Subject: [PATCH 2/2] fix: allow copying text outside the component (#3275) --- src/actions/actionClipboard.tsx | 3 ++- src/components/App.tsx | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/actions/actionClipboard.tsx b/src/actions/actionClipboard.tsx index fdbe41dc7..93dc36baf 100644 --- a/src/actions/actionClipboard.tsx +++ b/src/actions/actionClipboard.tsx @@ -17,7 +17,8 @@ export const actionCopy = register({ }; }, contextItemLabel: "labels.copy", - keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.C, + // don't supply a shortcut since we handle this conditionally via onCopy event + keyTest: undefined, }); export const actionCut = register({ diff --git a/src/components/App.tsx b/src/components/App.tsx index 7455e416a..9ce43b7a5 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1047,6 +1047,21 @@ class App extends React.Component { }); private onCopy = withBatchedUpdates((event: ClipboardEvent) => { + const activeSelection = document.getSelection(); + // if there's a selected text is outside the component, prevent our copy + // action + if ( + activeSelection?.anchorNode && + // it can happen that certain interactions will create a selection + // outside (or potentially inside) the component without actually + // selecting anything (i.e. the selection range is collapsed). Copying + // in such case wouldn't copy anything to the clipboard anyway, so prevent + // our copy handler only if the selection isn't collapsed + !activeSelection.isCollapsed && + !this.excalidrawContainerRef.current!.contains(activeSelection.anchorNode) + ) { + return; + } if (isWritableElement(event.target)) { return; } @@ -2118,6 +2133,14 @@ class App extends React.Component { ) => { event.persist(); + // remove any active selection when we start to interact with canvas + // (mainly, we care about removing selection outside the component which + // would prevent our copy handling otherwise) + const selection = document.getSelection(); + if (selection?.anchorNode) { + selection.removeAllRanges(); + } + this.maybeOpenContextMenuAfterPointerDownOnTouchDevices(event); this.maybeCleanupAfterMissingPointerUp(event);