Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a visual bug where imported images would appear with a half-pixel offset, particularly when added through a non-mouse-driven workflow like a file open dialog. The changes refine the coordinate transformation logic to ensure that images are always precisely aligned within the viewport, improving the accuracy of image placement. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes a half-pixel offset issue when importing images without a specific mouse position by using DAffine2::IDENTITY to default to the document origin. The change is applied to both PasteImage and PasteSvg message handlers. The fix appears correct. My only feedback is regarding code duplication between these two handlers, which could be refactored into a helper function to improve maintainability.
| let center_in_viewport = mouse.map_or(DAffine2::IDENTITY, |pos| { | ||
| let viewport_location: DVec2 = pos.into(); | ||
| let document_to_viewport = self.navigation_handler.calculate_offset_transform(viewport.center_in_viewport_space().into(), &self.document_ptz); | ||
| DAffine2::from_translation(document_to_viewport.inverse().transform_point2(viewport_location - viewport.offset().into_dvec2())) | ||
| }); |
There was a problem hiding this comment.
This logic for calculating center_in_viewport is identical to the logic for center_in_viewport_layerspace in the PasteImage message handler above (lines 667-671). To improve maintainability and reduce code duplication, consider extracting this logic into a private helper function within DocumentMessageHandler.
For example:
impl DocumentMessageHandler {
// ...
fn get_document_space_transform_from_mouse(&self, mouse: Option<ViewportPosition>, viewport: &ViewportMessageHandler) -> DAffine2 {
mouse.map_or(DAffine2::IDENTITY, |pos| {
let viewport_location: DVec2 = pos.into();
let document_to_viewport = self.navigation_handler.calculate_offset_transform(viewport.center_in_viewport_space().into(), &self.document_ptz);
DAffine2::from_translation(document_to_viewport.inverse().transform_point2(viewport_location - viewport.offset().into_dvec2()))
})
}
// ...
}Then you could call self.get_document_space_transform_from_mouse(mouse, viewport) in both PasteImage and PasteSvg message handlers.
There was a problem hiding this comment.
2 issues found across 1 file
Confidence score: 3/5
- There is a concrete regression risk in
editor/src/messages/portfolio/document/document_message_handler.rs: bothPasteImageandPasteSvgnow fall backmouse: Noneto document origin, which can place pasted content far from the user’s current view. - This is medium severity but high confidence (6/10, 8/10), so the PR likely remains workable yet carries noticeable user-facing paste behavior risk in existing documents.
- Pay close attention to
editor/src/messages/portfolio/document/document_message_handler.rs- verifymouse: Nonepaste placement logic so clipboard pastes stay visible in non-origin views.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="editor/src/messages/portfolio/document/document_message_handler.rs">
<violation number="1" location="editor/src/messages/portfolio/document/document_message_handler.rs:667">
P2: `PasteImage` now treats `mouse: None` as document origin for all flows, which regresses clipboard paste placement in existing documents.</violation>
<violation number="2" location="editor/src/messages/portfolio/document/document_message_handler.rs:721">
P2: `PasteSvg` applies the same `mouse: None -> origin` fallback, causing clipboard SVG paste to appear off-screen in non-origin views.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Fixes #3670