Skip to content

Fix bug with positioning new components#65

Merged
jrupp merged 1 commit into
mainfrom
position-bug
Jul 2, 2026
Merged

Fix bug with positioning new components#65
jrupp merged 1 commit into
mainfrom
position-bug

Conversation

@jrupp

@jrupp jrupp commented Jul 2, 2026

Copy link
Copy Markdown
Owner

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.

@jrupp jrupp requested a review from Copilot July 2, 2026 20:45
@jrupp jrupp added bug Something isn't working javascript Pull requests that update javascript code labels Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/model/componentGroup.js
Comment thread spec/support/something.spec.mjs
@jrupp jrupp merged commit 27b75bc into main Jul 2, 2026
5 checks passed
@jrupp jrupp deleted the position-bug branch July 2, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants