From 0e590ab5d77f1bf4e106ad37be8204bd623c283a Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Tue, 24 Jun 2025 19:23:06 +0200 Subject: [PATCH] Fix aspect ratio lock when resizing with Shift key Simplifies and corrects the logic for maintaining the original aspect ratio when resizing objects with the Shift key pressed. Ensures consistent behavior regardless of handle or direction. --- js/Canvas.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/js/Canvas.js b/js/Canvas.js index 3e52012..c300926 100644 --- a/js/Canvas.js +++ b/js/Canvas.js @@ -890,23 +890,12 @@ export class Canvas { if (isShiftPressed) { const originalAspectRatio = o.width / o.height; - if (handle.length === 2) { + const newAspectRatio = Math.abs(newWidth / newHeight); - const potentialWidth = Math.abs(newWidth); - const potentialHeight = Math.abs(newHeight); - - if (potentialWidth / originalAspectRatio > potentialHeight) { - newHeight = newWidth / originalAspectRatio; - } else { - newWidth = newHeight * originalAspectRatio; - } + if (Math.abs(newWidth) > Math.abs(newHeight) * originalAspectRatio) { + newHeight = (Math.sign(newHeight) || 1) * Math.abs(newWidth) / originalAspectRatio; } else { - - if (signX !== 0) { - newHeight = newWidth / originalAspectRatio; - } else { - newWidth = newHeight * originalAspectRatio; - } + newWidth = (Math.sign(newWidth) || 1) * Math.abs(newHeight) * originalAspectRatio; } }