浏览代码

Merge remote-tracking branch 'origin/master' into updatescene-name

Aakansha Doshi 4 年之前
父节点
当前提交
dcda7184d0
共有 4 个文件被更改,包括 27 次插入3 次删除
  1. 1 1
      CONTRIBUTING.md
  2. 2 1
      src/actions/actionClipboard.tsx
  3. 23 0
      src/components/App.tsx
  4. 1 1
      src/packages/utils/package.json

+ 1 - 1
CONTRIBUTING.md

@@ -5,7 +5,7 @@
 ### Option 1 - Manual
 ### Option 1 - Manual
 
 
 1. Fork and clone the repo
 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`
 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:
 > To keep `master` branch pointing to remote repository and make pull requests from branches on your fork. To do this, run:

+ 2 - 1
src/actions/actionClipboard.tsx

@@ -17,7 +17,8 @@ export const actionCopy = register({
     };
     };
   },
   },
   contextItemLabel: "labels.copy",
   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({
 export const actionCut = register({

+ 23 - 0
src/components/App.tsx

@@ -1058,6 +1058,21 @@ class App extends React.Component<ExcalidrawProps, AppState> {
   });
   });
 
 
   private onCopy = withBatchedUpdates((event: ClipboardEvent) => {
   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)) {
     if (isWritableElement(event.target)) {
       return;
       return;
     }
     }
@@ -2129,6 +2144,14 @@ class App extends React.Component<ExcalidrawProps, AppState> {
   ) => {
   ) => {
     event.persist();
     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.maybeOpenContextMenuAfterPointerDownOnTouchDevices(event);
     this.maybeCleanupAfterMissingPointerUp(event);
     this.maybeCleanupAfterMissingPointerUp(event);
 
 

+ 1 - 1
src/packages/utils/package.json

@@ -57,6 +57,6 @@
   "scripts": {
   "scripts": {
     "build:umd": "cross-env NODE_ENV=production webpack --config webpack.prod.config.js",
     "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",
     "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"
   }
   }
 }
 }