feat(simulator): add fit view to selection helper#872
feat(simulator): add fit view to selection helper#872yashveer-1 wants to merge 5 commits intoCircuitVerse:mainfrom
Conversation
✅ Deploy Preview for circuitverse ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughAdds viewport-fitting for selections: new 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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 `@src/simulator/src/canvasApi.js`:
- Around line 85-104: fitToSelection can call globalScope.centerFocus(true)
after findDimensions even when findDimensions found no non-wire bounds (e.g.,
wires-only selection), causing undefined bounds; modify fitToSelection to detect
missing/invalid computed bounds after buildSelectionScope and findDimensions
(inspect whatever property findDimensions sets on the scope or a bounds return
value) and fall back to the empty-selection behavior (call
globalScope.centerFocus(false) or compute overall default bounds) instead of
calling centerFocus(true). Specifically, update fitToSelection to check the
selectionScope or the bounds result from findDimensions before invoking
globalScope.centerFocus(true), and call globalScope.centerFocus(false) when
bounds are absent.
🧹 Nitpick comments (1)
src/simulator/src/listeners.js (1)
61-80: Return a copy for multi‑selection to avoid external mutation.
Since this is exported, returning the internal array by reference risks accidental mutation by callers.♻️ Suggested change
- return simulationArea.multipleObjectSelections + return simulationArea.multipleObjectSelections.slice()
|
All changes are complete. |
|
@tachyons @Nihal4777 @ThatDeparted2061 kindly review ! |
|
Hey @yashveer-1 can you please add fixes # . Assuming you accidently removed that line while creating a pr :)) |

Describe the changes you have made in this PR -
This PR adds a Fit View to Selection capability to the simulator.
The change reuses existing engine utilities (
findDimensions,centerFocus) by constructing a temporary selection scope, keeping the behavior consistent with current canvas logic.Screenshots of the UI changes (If any) -
111111111.mp4
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
This change improves navigation in large or complex circuits by allowing users to quickly focus on the elements they are actively working on.
I considered directly mutating the global simulation scope to compute bounds, but that approach risked unintended side effects. Instead, I chose to construct a temporary selection-only scope that mirrors the structure expected by existing utilities. This allowed me to reuse
findDimensions()without modifying global circuit state.The core logic is handled by:
buildSelectionScope()— creates a derived scope containing only selected elementsfitToSelection()— computes bounds using the derived scope and delegates centering/zooming tocenterFocus()This approach keeps the change minimal, predictable, and consistent with existing engine patterns.
Checklist before requesting a review
Note: I have enabled Allow edits from maintainers.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.