Browse Source

Fix binding disabling when taking screenshots on macOS (#2129)

* Fix binding disabling when taking screenshots on macOS
* Update snapshot for cmd+click test
vanilla_orig
Michal Srb 5 years ago
parent
commit
15e4b51bb1
No account linked to committer's email address

+ 11
- 0
src/components/App.tsx View File

@@ -171,6 +171,7 @@ import {
171 171
   isLinearElementSimpleAndAlreadyBound,
172 172
   isBindingEnabled,
173 173
   updateBoundElements,
174
+  shouldEnableBindingForPointerEvent,
174 175
 } from "../element/binding";
175 176
 import { MaybeTransformHandleType } from "../element/transformHandles";
176 177
 
@@ -2220,6 +2221,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
2220 2221
     }
2221 2222
 
2222 2223
     this.clearSelectionIfNotUsingSelection();
2224
+    this.updateBindingEnabledOnPointerMove(event);
2223 2225
 
2224 2226
     if (this.handleSelectionOnPointerDown(event, pointerDownState)) {
2225 2227
       return;
@@ -3484,6 +3486,15 @@ class App extends React.Component<ExcalidrawProps, AppState> {
3484 3486
     });
3485 3487
   }
3486 3488
 
3489
+  private updateBindingEnabledOnPointerMove = (
3490
+    event: React.PointerEvent<HTMLCanvasElement>,
3491
+  ) => {
3492
+    const shouldEnableBinding = shouldEnableBindingForPointerEvent(event);
3493
+    if (this.state.isBindingEnabled !== shouldEnableBinding) {
3494
+      this.setState({ isBindingEnabled: shouldEnableBinding });
3495
+    }
3496
+  };
3497
+
3487 3498
   private maybeSuggestBindingAtCursor = (pointerCoords: {
3488 3499
     x: number;
3489 3500
     y: number;

+ 7
- 0
src/element/binding.ts View File

@@ -21,6 +21,7 @@ import { mutateElement } from "./mutateElement";
21 21
 import Scene from "../scene/Scene";
22 22
 import { LinearElementEditor } from "./linearElementEditor";
23 23
 import { tupleToCoors } from "../utils";
24
+import { KEYS } from "../keys";
24 25
 
25 26
 export type SuggestedBinding =
26 27
   | NonDeleted<ExcalidrawBindableElement>
@@ -32,6 +33,12 @@ export type SuggestedPointBinding = [
32 33
   NonDeleted<ExcalidrawBindableElement>,
33 34
 ];
34 35
 
36
+export const shouldEnableBindingForPointerEvent = (
37
+  event: React.PointerEvent<HTMLCanvasElement>,
38
+) => {
39
+  return !event[KEYS.CTRL_OR_CMD];
40
+};
41
+
35 42
 export const isBindingEnabled = (appState: AppState): boolean => {
36 43
   return appState.isBindingEnabled;
37 44
 };

+ 1
- 1
src/tests/__snapshots__/regressionTests.test.tsx.snap View File

@@ -907,7 +907,7 @@ Object {
907 907
   "exportBackground": true,
908 908
   "gridSize": null,
909 909
   "height": 768,
910
-  "isBindingEnabled": true,
910
+  "isBindingEnabled": false,
911 911
   "isCollaborating": false,
912 912
   "isLibraryOpen": false,
913 913
   "isLoading": false,

Loading…
Cancel
Save