Jelajahi Sumber

fix: disable contextmenu on non-secondary `pen` events or `touch` (#4675)

David Luzar 3 tahun lalu
induk
melakukan
5007df6522
2 mengubah file dengan 11 tambahan dan 1 penghapusan
  1. 10 0
      src/components/App.tsx
  2. 1 1
      src/constants.ts

+ 10 - 0
src/components/App.tsx

@@ -5035,6 +5035,16 @@ class App extends React.Component<AppProps, AppState> {
   ) => {
     event.preventDefault();
 
+    if (
+      (event.nativeEvent.pointerType === "touch" ||
+        (event.nativeEvent.pointerType === "pen" &&
+          // always allow if user uses a pen secondary button
+          event.button !== POINTER_BUTTON.SECONDARY)) &&
+      this.state.elementType !== "selection"
+    ) {
+      return;
+    }
+
     const { x, y } = viewportCoordsToSceneCoords(event, this.state);
     const element = this.getElementAtPosition(x, y, { preferSelected: true });
 

+ 1 - 1
src/constants.ts

@@ -24,7 +24,7 @@ export const POINTER_BUTTON = {
   WHEEL: 1,
   SECONDARY: 2,
   TOUCH: -1,
-};
+} as const;
 
 export enum EVENT {
   COPY = "copy",