Skip to content

Right click threshold#5686

Open
filippo-fanni wants to merge 2 commits intoxyflow:mainfrom
oktima:right-click-threshold
Open

Right click threshold#5686
filippo-fanni wants to merge 2 commits intoxyflow:mainfrom
oktima:right-click-threshold

Conversation

@filippo-fanni
Copy link
Copy Markdown
Contributor

@filippo-fanni filippo-fanni commented Jan 26, 2026

This attempts to solve #5614

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 26, 2026

⚠️ No Changeset found

Latest commit: aff29e3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 26, 2026

Walkthrough

The pull request introduces distance-based threshold logic for distinguishing right-click context menu events from drag pan interactions. Changes include adding a startPosition field to track initial pan coordinates in ZoomPanValues, a new paneClickDistance parameter to PanZoomParams that defines the activation threshold, and updated event handler logic that computes the squared distance between the start position and current position during pan-zoom operations. The right-click activation now requires both right-click detection and the distance traveled to exceed the threshold. An example file is updated to demonstrate usage of the new onPaneContextMenu handler and panOnDrag prop.

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate whether it relates to the changeset. Add a description explaining the purpose and motivation for implementing the right-click threshold feature and its behavioral impact.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Right click threshold' directly aligns with the main changes: adding distance-based thresholds for right-click context menu activation across multiple files.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +206 to 221
// 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
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant