refactor(editor): simplify putContentOntoCurrentPage paste-parent and positioning logic#8057
Conversation
… positioning logic Replace the convoluted paste-parent selection and positioning logic with clearer, well-separated code paths for paste-at-cursor vs standard paste. - Generalize frame-specific checks to use canReceiveNewChildrenOfType - Replace lowest-depth ancestor walk with findShapeAncestor - Replace isDuplicating detection with shapeIdMap.has() guard - Use collides() instead of includes() for viewport overlap check - Add center-containment filter to auto-reparent callback to prevent edge-only overlap from swallowing pasted shapes into adjacent frames - Remove frame-deduplication offset logic
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| pasteParentId = this.getShape(pasteParentId)!.parentId | ||
| if (selectedParent) { | ||
| pasteParentId = selectedParent.id | ||
| } |
There was a problem hiding this comment.
Paste can target offscreen selected parent
Medium Severity
The standard paste path no longer checks whether the chosen selectedParent (or its ancestors) is inside the viewport before setting pasteParentId. This can paste new shapes into an offscreen container and then center them within that container, making the paste appear to “do nothing” because the result is not visible.
| if (!candidate) { | ||
| selectedParent = null | ||
| break | ||
| } |
There was a problem hiding this comment.
Non-null assertion may crash during paste
High Severity
candidate computation uses this.getShape(shape.parentId)! when shape.parentId is a shape id. If the parent shape is missing (e.g., transiently deleted/out-of-sync state), this dereference can throw during paste, crashing the action instead of falling back to currentPageId.
|
Worth a shot addressing some of the claude comments but as far as I'm concerned, this is working for the "paste at pointer" feature and the test are passing (in comparison with my "fix" which broke a lot of unrelated tests) |
|
need to fire kick out children when pasting into a paste parent |
Import and call kickoutOccludedShapes during paste to relocate pasted root shapes that end up outside their parent container. The change computes which pasted root shapes are children of a container (not the page) and that do not contain any newly pasted children, then kicks out those shapes to avoid them being occluded or unintentionally nested. Adds a test that copies three spaced rectangles, pastes them into a smaller frame, and asserts the centered shape remains a child while the outlying shapes are moved to the page.


In order to make the paste logic in
putContentOntoCurrentPageeasier to reason about and extend, this PR replaces the convoluted paste-parent selection and positioning code with clearer, well-separated logic paths.Change type
improvementTest plan
Release notes
canReceiveNewChildrenOfTypeinstead of frame-specific checksNote
Medium Risk
Changes core paste/reparenting and positioning logic, which can subtly affect many copy/paste scenarios across containers and frames despite test coverage.
Overview
Refactors
Editor.putContentOntoCurrentPagepaste behavior into clearer paths for paste-at-cursor, standard paste, and preserve-position pastes, usingcanReceiveNewChildrenOfType(with optional chaining) to choose a valid container from the selection/ancestors and avoiding pasting content into itself (duplicate-container case).Updates positioning rules to center pastes within the chosen parent, keep coordinates for
preservePosition, otherwise choose between original vs viewport center based on viewport overlap, and skips theupdateShapespass when the computed offset is zero.Tightens page-level auto-reparenting into frames by filtering out source shapes and requiring the pasted shape’s bounds center to be inside the candidate parent (preventing reparenting on edge-only overlap); updates
paste.test.tsexpectations accordingly.Written by Cursor Bugbot for commit c7e5719. This will update automatically on new commits. Configure here.