Skip to content

Commit

Permalink
fix: preventDefault onContext & react only on button=0 clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Kofler-Hofer committed Apr 22, 2024
1 parent 153607d commit 399eb62
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/web/pivotControls/AxisArrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export const AxisArrow: React.FC<{ direction: THREE.Vector3; axis: 0 | 1 | 2 }>

const onPointerDown = React.useCallback(
(e: ThreeEvent<PointerEvent>) => {
if (e.button !== 0) {
e.stopPropagation()
return
}
if (annotations) {
divRef.current.innerText = `${translation.current[axis].toFixed(2)}`
divRef.current.style.display = 'block'
Expand Down Expand Up @@ -116,6 +120,10 @@ export const AxisArrow: React.FC<{ direction: THREE.Vector3; axis: 0 | 1 | 2 }>

const onPointerUp = React.useCallback(
(e: ThreeEvent<PointerEvent>) => {
if (e.button !== 0) {
e.stopPropagation()
return
}
if (annotations) {
divRef.current.style.display = 'none'
}
Expand Down Expand Up @@ -154,6 +162,10 @@ export const AxisArrow: React.FC<{ direction: THREE.Vector3; axis: 0 | 1 | 2 }>
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onPointerOut={onPointerOut}
onContextMenu={(e) => {
e.stopPropagation()
e.nativeEvent.preventDefault()
}}
>
{annotations && (
<Html position={[0, -coneLength, 0]}>
Expand Down
12 changes: 12 additions & 0 deletions src/web/pivotControls/AxisRotator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export const AxisRotator: React.FC<{ dir1: THREE.Vector3; dir2: THREE.Vector3; a

const onPointerDown = React.useCallback(
(e: ThreeEvent<PointerEvent>) => {
if (e.button !== 0) {
e.stopPropagation()
return
}
if (annotations) {
divRef.current.innerText = `${toDegrees(angle.current).toFixed(0)}º`
divRef.current.style.display = 'block'
Expand Down Expand Up @@ -163,6 +167,10 @@ export const AxisRotator: React.FC<{ dir1: THREE.Vector3; dir2: THREE.Vector3; a

const onPointerUp = React.useCallback(
(e: ThreeEvent<PointerEvent>) => {
if (e.button !== 0) {
e.stopPropagation()
return
}
if (annotations) {
divRef.current.style.display = 'none'
}
Expand Down Expand Up @@ -207,6 +215,10 @@ export const AxisRotator: React.FC<{ dir1: THREE.Vector3; dir2: THREE.Vector3; a
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onPointerOut={onPointerOut}
onContextMenu={(e) => {
e.stopPropagation()
e.nativeEvent.preventDefault()
}}
matrix={matrixL}
matrixAutoUpdate={false}
>
Expand Down
12 changes: 12 additions & 0 deletions src/web/pivotControls/PlaneSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export const PlaneSlider: React.FC<{ dir1: THREE.Vector3; dir2: THREE.Vector3; a

const onPointerDown = React.useCallback(
(e: ThreeEvent<PointerEvent>) => {
if (e.button !== 0) {
e.stopPropagation()
return
}
if (annotations) {
divRef.current.innerText = `${translation.current[(axis + 1) % 3].toFixed(2)}, ${translation.current[
(axis + 2) % 3
Expand Down Expand Up @@ -144,6 +148,10 @@ export const PlaneSlider: React.FC<{ dir1: THREE.Vector3; dir2: THREE.Vector3; a

const onPointerUp = React.useCallback(
(e: ThreeEvent<PointerEvent>) => {
if (e.button !== 0) {
e.stopPropagation()
return
}
if (annotations) {
divRef.current.style.display = 'none'
}
Expand Down Expand Up @@ -208,6 +216,10 @@ export const PlaneSlider: React.FC<{ dir1: THREE.Vector3; dir2: THREE.Vector3; a
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onPointerOut={onPointerOut}
onContextMenu={(e) => {
e.stopPropagation()
e.nativeEvent.preventDefault()
}}
scale={length}
userData={userData}
>
Expand Down
12 changes: 12 additions & 0 deletions src/web/pivotControls/ScalingSphere.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const ScalingSphere: React.FC<{ direction: THREE.Vector3; axis: 0 | 1 | 2

const onPointerDown = React.useCallback(
(e: ThreeEvent<PointerEvent>) => {
if (e.button !== 0) {
e.stopPropagation()
return
}
if (annotations) {
divRef.current.innerText = `${scaleCur.current.toFixed(2)}`
divRef.current.style.display = 'block'
Expand Down Expand Up @@ -142,6 +146,10 @@ export const ScalingSphere: React.FC<{ direction: THREE.Vector3; axis: 0 | 1 | 2

const onPointerUp = React.useCallback(
(e: ThreeEvent<PointerEvent>) => {
if (e.button !== 0) {
e.stopPropagation()
return
}
if (annotations) {
divRef.current.style.display = 'none'
}
Expand Down Expand Up @@ -180,6 +188,10 @@ export const ScalingSphere: React.FC<{ direction: THREE.Vector3; axis: 0 | 1 | 2
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onPointerOut={onPointerOut}
onContextMenu={(e) => {
e.stopPropagation()
e.nativeEvent.preventDefault()
}}
>
{annotations && (
<Html position={[0, position / 2, 0]}>
Expand Down

0 comments on commit 399eb62

Please sign in to comment.