Right click threshold#5686
Conversation
|
WalkthroughThe pull request introduces distance-based threshold logic for distinguishing right-click context menu events from drag pan interactions. Changes include adding a 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/system/src/xypanzoom/eventhandler.ts`:
- Around line 206-221: Normalize paneClickDistance to a non-negative number
before squaring so the distance comparison used to set
zoomPanValues.usedRightMouseButton behaves correctly for undefined/NaN/negative
values; convert/validate paneClickDistance (e.g., coerce to Number, fallback to
0, and clamp with Math.max(0,...)) and use that normalized value (e.g.,
normalizedPaneClickDistance) in the squared comparison instead of
paneClickDistance * paneClickDistance while keeping the rest of the logic
(isRightClickPan, onPaneContextMenu, zoomPanValues.mouseButton) unchanged.
| // Calculate distance from start position for right-click context menu threshold | ||
| let squaredDistance = 0; | ||
| if (zoomPanValues.startPosition && event.sourceEvent) { | ||
| const currentX = event.sourceEvent.clientX ?? event.sourceEvent.touches?.[0]?.clientX ?? 0; | ||
| const currentY = event.sourceEvent.clientY ?? event.sourceEvent.touches?.[0]?.clientY ?? 0; | ||
| const dx = currentX - zoomPanValues.startPosition.x; | ||
| const dy = currentY - zoomPanValues.startPosition.y; | ||
| squaredDistance = dx * dx + dy * dy; | ||
| } | ||
|
|
||
| // Only mark as used when distance exceeds paneClickDistance threshold | ||
| zoomPanValues.usedRightMouseButton = !!( | ||
| onPaneContextMenu && isRightClickPan(panOnDrag, zoomPanValues.mouseButton ?? 0) | ||
| onPaneContextMenu && | ||
| isRightClickPan(panOnDrag, zoomPanValues.mouseButton ?? 0) && | ||
| squaredDistance > paneClickDistance * paneClickDistance | ||
| ); |
There was a problem hiding this comment.
Normalize paneClickDistance before squaring.
If paneClickDistance is undefined/NaN/negative, the comparison yields NaN and usedRightMouseButton never flips, so a right-click drag could still open the context menu. Consider normalizing to the same effective distance used for clickDistance (0 for invalid).
🩹 Suggested fix
- zoomPanValues.usedRightMouseButton = !!(
- onPaneContextMenu &&
- isRightClickPan(panOnDrag, zoomPanValues.mouseButton ?? 0) &&
- squaredDistance > paneClickDistance * paneClickDistance
- );
+ const effectivePaneClickDistance =
+ Number.isFinite(paneClickDistance) && paneClickDistance >= 0 ? paneClickDistance : 0;
+
+ zoomPanValues.usedRightMouseButton = !!(
+ onPaneContextMenu &&
+ isRightClickPan(panOnDrag, zoomPanValues.mouseButton ?? 0) &&
+ squaredDistance > effectivePaneClickDistance * effectivePaneClickDistance
+ );🤖 Prompt for AI Agents
In `@packages/system/src/xypanzoom/eventhandler.ts` around lines 206 - 221,
Normalize paneClickDistance to a non-negative number before squaring so the
distance comparison used to set zoomPanValues.usedRightMouseButton behaves
correctly for undefined/NaN/negative values; convert/validate paneClickDistance
(e.g., coerce to Number, fallback to 0, and clamp with Math.max(0,...)) and use
that normalized value (e.g., normalizedPaneClickDistance) in the squared
comparison instead of paneClickDistance * paneClickDistance while keeping the
rest of the logic (isRightClickPan, onPaneContextMenu,
zoomPanValues.mouseButton) unchanged.
This attempts to solve #5614