Skip to content

fix: prevent shapes from shrinking to zero via keyboard nudge#3949

Open
Chetansahney wants to merge 2 commits intoGraphiteEditor:masterfrom
Chetansahney:fix/nudge-zero-size
Open

fix: prevent shapes from shrinking to zero via keyboard nudge#3949
Chetansahney wants to merge 2 commits intoGraphiteEditor:masterfrom
Chetansahney:fix/nudge-zero-size

Conversation

@Chetansahney
Copy link

Fixes #3947

Added a 1px floor to the keyboard nudge math to stop shapes from shrinking to zero and getting stuck

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 addresses a critical bug where keyboard nudging could cause shapes to shrink to a zero-pixel size, making them unselectable and stuck. The changes introduce a more robust calculation for shape enlargement, ensuring that shapes maintain a minimum dimension of 1 pixel. This significantly improves the user experience by preventing unintended shape disappearance and enhancing the reliability of keyboard-based manipulation.

Highlights

  • Keyboard Nudge Behavior: Implemented a fix to prevent shapes from shrinking to zero dimensions when nudged using keyboard inputs, resolving an issue where shapes could become stuck.
  • Resizing Logic: Refactored the enlargement factor calculation to ensure a minimum size of 1px, preventing division by zero errors and improving the stability of shape resizing.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where shapes could shrink to zero size when nudged with the keyboard. The change correctly clamps both the original and new sizes of the shape to a minimum of 1px before calculating the resize factor. This prevents division by zero and ensures shapes don't disappear. The logic is sound, but I have a suggestion to improve a comment for better code clarity.

I am having trouble creating individual review comments. Click here to see my feedback.

editor/src/messages/portfolio/document/document_message_handler.rs (2130)

medium

This comment is a bit vague and doesn't explain the fix. To improve code clarity for future maintainers, consider replacing it with a comment that explains why the new math is correct, specifically mentioning the clamping of both original and new sizes to prevent division by zero and shapes from shrinking to zero size.

		// To prevent division by zero or shapes shrinking to nothing, we clamp both the original and new sizes to a minimum of 1px before calculating the enlargement factor.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

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: clamping the denominator to 1 makes scale factors too small for sub-1px selections, so tiny objects resize much less than expected.
  • A second medium-severity issue in the same handler can cause translation drift: scale is computed from clamped resize delta while position/pivot still use raw keyboard delta when min-size clamping is hit.
  • Given two high-confidence, user-visible resize/transform inconsistencies (both 6/10), this is a moderate merge risk rather than a merge-blocker.
  • Pay close attention to editor/src/messages/portfolio/document/document_message_handler.rs - resize scaling and pivot/position delta handling can diverge under min-size clamps.
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:2135">
P2: Clamping the current size to 1 in the denominator makes resize scaling incorrect for sub-1px objects, causing tiny selections to resize very weakly.</violation>

<violation number="2" location="editor/src/messages/portfolio/document/document_message_handler.rs:2137">
P2: Clamped scale uses reduced resize delta, but position/pivot still use raw keyboard delta, causing incorrect translation when min-size clamp is hit.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

if resize_opposite_corner != opposite_y { -delta_y } else { delta_y },
);
let enlargement_factor = (enlargement + size) / size;
let clamped_size = size.max(DVec2::ONE);
Copy link
Contributor

Choose a reason for hiding this comment

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

P2: Clamping the current size to 1 in the denominator makes resize scaling incorrect for sub-1px objects, causing tiny selections to resize very weakly.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/portfolio/document/document_message_handler.rs, line 2135:

<comment>Clamping the current size to 1 in the denominator makes resize scaling incorrect for sub-1px objects, causing tiny selections to resize very weakly.</comment>

<file context>
@@ -2127,14 +2127,14 @@ impl DocumentMessageHandler {
 			if resize_opposite_corner != opposite_y { -delta_y } else { delta_y },
 		);
-		let enlargement_factor = (enlargement + size) / size;
+		let clamped_size = size.max(DVec2::ONE);
+		let clamped_new_size = (size + enlargement).max(DVec2::ONE);
+		let enlargement_factor = clamped_new_size / clamped_size;
</file context>

let enlargement_factor = (enlargement + size) / size;
let clamped_size = size.max(DVec2::ONE);
let clamped_new_size = (size + enlargement).max(DVec2::ONE);
let enlargement_factor = clamped_new_size / clamped_size;
Copy link
Contributor

Choose a reason for hiding this comment

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

P2: Clamped scale uses reduced resize delta, but position/pivot still use raw keyboard delta, causing incorrect translation when min-size clamp is hit.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/portfolio/document/document_message_handler.rs, line 2137:

<comment>Clamped scale uses reduced resize delta, but position/pivot still use raw keyboard delta, causing incorrect translation when min-size clamp is hit.</comment>

<file context>
@@ -2127,14 +2127,14 @@ impl DocumentMessageHandler {
-		let enlargement_factor = (enlargement + size) / size;
+		let clamped_size = size.max(DVec2::ONE);
+		let clamped_new_size = (size + enlargement).max(DVec2::ONE);
+		let enlargement_factor = clamped_new_size / clamped_size;
 
 		let position = DVec2::new(
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resizing a shape to zero locks it permanently

1 participant