@@ -42,7 +42,9 @@ public void OnMouseMove(Point position, Canvas canvas, MouseButtonState leftButt
4242 if ( _isCreatingRectangle && _currentRectangle != null && _rectangleStartPoint . HasValue )
4343 {
4444 // Update rectangle dimensions to follow cursor
45- UpdateRectangle ( _rectangleStartPoint . Value , position ) ;
45+ // Check if Shift key is held down for perfect square
46+ bool isShiftPressed = Keyboard . IsKeyDown ( Key . LeftShift ) || Keyboard . IsKeyDown ( Key . RightShift ) ;
47+ UpdateRectangle ( _rectangleStartPoint . Value , position , isShiftPressed ) ;
4648 }
4749 }
4850
@@ -117,7 +119,7 @@ private void StartNewRectangle(Point startPoint, Canvas canvas)
117119 _logger . LogInformation ( "Rectangle started at ({X:F0}, {Y:F0})" , startPoint . X , startPoint . Y ) ;
118120 }
119121
120- private void UpdateRectangle ( Point startPoint , Point currentPoint )
122+ private void UpdateRectangle ( Point startPoint , Point currentPoint , bool isPerfectSquare = false )
121123 {
122124 if ( _currentRectangle == null )
123125 return ;
@@ -128,6 +130,17 @@ private void UpdateRectangle(Point startPoint, Point currentPoint)
128130 double width = Math . Abs ( currentPoint . X - startPoint . X ) ;
129131 double height = Math . Abs ( currentPoint . Y - startPoint . Y ) ;
130132
133+ // If Shift is held, make it a perfect square (width = height = min dimension)
134+ // Note: Uses Math.Min (not Math.Max like CircleTool) so the square fits within
135+ // the dragged bounding box, making the final size more predictable and visible
136+ // to the user as they drag. This matches the behavior specified in the issue.
137+ if ( isPerfectSquare )
138+ {
139+ double size = Math . Min ( width , height ) ;
140+ width = size ;
141+ height = size ;
142+ }
143+
131144 Canvas . SetLeft ( _currentRectangle , left ) ;
132145 Canvas . SetTop ( _currentRectangle , top ) ;
133146 _currentRectangle . Width = width ;
@@ -138,7 +151,9 @@ private void FinishRectangle(Point endPoint)
138151 {
139152 if ( _currentRectangle != null && _rectangleStartPoint . HasValue )
140153 {
141- UpdateRectangle ( _rectangleStartPoint . Value , endPoint ) ;
154+ // Check if Shift was held on the final click
155+ bool isShiftPressed = Keyboard . IsKeyDown ( Key . LeftShift ) || Keyboard . IsKeyDown ( Key . RightShift ) ;
156+ UpdateRectangle ( _rectangleStartPoint . Value , endPoint , isShiftPressed ) ;
142157 _logger . LogInformation ( "Rectangle finished at ({X:F0}, {Y:F0})" , endPoint . X , endPoint . Y ) ;
143158 }
144159
0 commit comments