Skip to content

Conversation

@Nakshatra480
Copy link
Contributor

@Nakshatra480 Nakshatra480 commented Jan 29, 2026

What

Right click → Delete (and Copy/Cut) was not working when the component was in the lower part of the canvas. It worked in the upper part and keyboard Delete still worked everywhere.

Why

Selection for the context menu actions was coming from the mousedown that opened the menu. In the lower part of the board that selection wasn’t reliable, so lastSelected was wrong or missing when the user chose Delete.

How

Before showing the context menu we now sync selection to the right click position: convert that position to canvas/simulation coords (same as panStart in listeners), set the relevant simulationArea mouse fields, and run update(globalScope, true) so the element under the cursor becomes lastSelected. That way Delete/Copy/Cut always target the element the user right-clicked on, no matter where it is on the canvas.

Closes #829

Summary by CodeRabbit

  • Bug Fixes

    • Context menu now syncs with current selection and mouse state so menus reliably appear in the correct spot.
    • Canvas/selection coordinates are refreshed before showing the menu, reducing stale or misaligned menus.
  • Style

    • Context menu visual layout and sizing updated for more stable positioning and improved appearance.
  • Behavior Changes

    • Multi-selection deletion logic adjusted, affecting which items can be removed in batch actions.

@netlify
Copy link

netlify bot commented Jan 29, 2026

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit c8a4765
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/6983c05be1aa870008bb74ee
😎 Deploy Preview https://deploy-preview-893--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 17 (🔴 down 30 from production)
Accessibility: 73 (no change from production)
Best Practices: 92 (no change from production)
SEO: 82 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

Walkthrough

Imports were extended to include update alongside updateCanvasSet. A new constant UNIT = 10 and a helper syncSelectionToContextMenuPosition() were added; the helper reads canvas bounds and device pixel ratio, computes and stores raw and scaled mouse/canvas coordinates on simulationArea (mouseDownRawX/Y, mouseDownX/Y, mouseRawX/Y, mouseXf/Yf), toggles mouseDown, calls update(globalScope, true), and restores state. showContextMenu() now invokes this helper before positioning. The context menu root element now suppresses mousedown propagation (@mousedown.stop), and CSS for #contextMenu layout, sizing, and shadowing was revised. Multi-selection deletion logic was adjusted by removing the Node type check.

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the fix: right-click delete functionality in the lower part of the board, directly addressing the bug reported in issue #829.
Linked Issues check ✅ Passed The changes fully implement the requirements from issue #829: synchronized selection to cursor position before context menu display, ensured consistent right-click delete behavior across the canvas, and made Delete/Copy/Cut target the correct element regardless of position.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the right-click delete issue: canvas coordinate synchronization, context menu positioning/styling, and mouse state preservation, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@Nakshatra480 Nakshatra480 force-pushed the fix/right-click-delete-lower-board-829 branch from f29fa78 to 39aa20f Compare January 29, 2026 18:40
Sync selection to context menu position so Delete/Copy/Cut work everywhere.
@Nakshatra480 Nakshatra480 force-pushed the fix/right-click-delete-lower-board-829 branch from 39aa20f to 9c4f4ff Compare January 29, 2026 18:45
Copy link
Contributor

@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: 2

🤖 Fix all issues with AI agents
In `@src/simulator/src/ux.js`:
- Around line 58-77: In syncSelectionToContextMenuPosition(), preserve the
previous simulationArea.mouseDown value before setting it to true, then call
update(globalScope, true), and finally restore simulationArea.mouseDown to the
saved value to avoid leaving the simulator in a forced “dragging” state; locate
the assignments to simulationArea.mouseDown in the function and wrap them with a
temporary variable (e.g., prevMouseDown) to save and restore around the update
call.

In `@v1/src/simulator/src/ux.js`:
- Around line 58-77: In syncSelectionToContextMenuPosition, save the current
simulationArea.mouseDown value to a temp variable before setting
simulationArea.mouseDown = true, call update(globalScope, true), and then
restore simulationArea.mouseDown to the saved value so the forced sync for
contextmenu does not leave a persistent "mouseDown" state; update the function
around the simulationArea.mouseDown assignments to perform this save/restore.

@Nakshatra480
Copy link
Contributor Author

hey @Nihal4777 @tachyons please review the changes and merge them if possible thanks

Copy link
Member

@Nihal4777 Nihal4777 left a comment

Choose a reason for hiding this comment

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

I noticed that when the context menu opens in the lower part of the canvas, it renders upward. However, the outside-click detection logic assumes the menu always opens downward (using ctxPos.y to ctxPos.y + offsetHeight). Because of this, clicks on menu items are incorrectly treated as clicks outside the menu, causing it to close before the item click handler runs.

Preserve simulationArea.mouseDown value in syncSelectionToContextMenuPosition() to avoid leaving the simulator in a forced 'dragging' state after right click operations. Changed variable name from wasMouseDown to prevMouseDown for clarity.
@Nakshatra480
Copy link
Contributor Author

Nakshatra480 commented Jan 31, 2026

@Nihal4777 I have implemented the fix by changing wasMouseDown to prevMouseDown in both ux.js files. This ensures proper mouse state preservation during right click operations, preventing the persistent dragging state. The changes maintain consistency and resolve the lower board area issue.

…nt propagation)

- Fixed DPR coordinate calculation using window.devicePixelRatio instead of undefined global
- Increased context menu z-index to 1000 to ensure clicks reach menu items above canvas
- Added @mousedown.stop to prevent canvas deselection when clicking context menu

The original PR code had an undefined DPR variable causing NaN coordinates.
Additionally, the canvas was intercepting menu clicks and deselecting components
before Delete could execute, especially in lower canvas where menu appeared far
from the selected component.
@Nakshatra480
Copy link
Contributor Author

Hi @Nihal4777 pls review this PR, changes are properly working.

Screen.Recording.2026-02-05.at.3.35.46.AM.mov

thanks for you time

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.

🐞Bug: right click delete doesn't work in the lower part of the board

2 participants