Fix bug with positioning new components#65
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes component placement behaviors that were dependent on hardcoded coordinates and zoom-related coordinate-space mixups, improving the “add component” and “duplicate group” user experience across different zoom/pan states.
Changes:
- Center newly added components (with or without connections) in the user’s current viewport, including updated grid-snapping logic.
- Fix width calculation for “duplicate next to” positioning by converting group bounds correctly into layer-local space.
- Add/adjust Jasmine specs to validate viewport-centered placement and zoom-independent duplication behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/model/componentGroup.js |
Adjusts group width computation for “next to” positioning using correct local coordinates. |
src/controller/layoutController.js |
Centers new component placement in the viewport and refines snap-to-grid behavior. |
spec/support/something.spec.mjs |
Updates and adds tests for viewport centering, snap offsets, and zoom-independent duplication. |
CLAUDE.md |
Updates the documented spec count. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes https://bricklayouts.canny.io/feature-requests/p/table-adding-places-new-items-far-away
When a new component is added without anything selected, the position is calculated using hardcoded magic numbers (150, 274 and 512, 384) that were designed for a specific zoom/position scenario. This results in poor placement at any other zoom level or workspace position. The fix centers new components in the user's viewport instead.
Additionally, there's a zoom-dependent bug when duplicating a group of components with no open connections — the "to the right" offset gets multiplied/divided by the zoom level due to a coordinate space mixup.