Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PivotControls - preventDefault onContext & react only on button=0 clicks #1932

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading