From 5007df6522c39b938c83bb46bd83eb35a5cf5a8e Mon Sep 17 00:00:00 2001 From: David Luzar Date: Mon, 7 Feb 2022 20:01:36 +0100 Subject: [PATCH] fix: disable contextmenu on non-secondary `pen` events or `touch` (#4675) --- src/components/App.tsx | 10 ++++++++++ src/constants.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index ef89c646..f49c0ca3 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -5035,6 +5035,16 @@ class App extends React.Component { ) => { 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 }); diff --git a/src/constants.ts b/src/constants.ts index e27044f9..c5a8afb8 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -24,7 +24,7 @@ export const POINTER_BUTTON = { WHEEL: 1, SECONDARY: 2, TOUCH: -1, -}; +} as const; export enum EVENT { COPY = "copy",