From d9ac5546ddde3add1619b00061eccccb7f75429d Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Sat, 21 Jun 2025 00:25:09 +0200 Subject: [PATCH] Keep Proportion with shift --- js/Canvas.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/js/Canvas.js b/js/Canvas.js index d276bbe..67d4eaf 100644 --- a/js/Canvas.js +++ b/js/Canvas.js @@ -560,7 +560,7 @@ export class Canvas { startCanvasMove(worldCoords) { this.interaction.mode = 'movingCanvas'; - this.interaction.dragStart = { ...worldCoords }; + this.interaction.dragStart = {...worldCoords}; const initialX = this.snapToGrid(worldCoords.x - this.width / 2); const initialY = this.snapToGrid(worldCoords.y - this.height / 2); @@ -701,6 +701,29 @@ export class Canvas { let newWidth = vecX * cos + vecY * sin; let newHeight = vecY * cos - vecX * sin; + if (isShiftPressed) { + const originalAspectRatio = o.width / o.height; + if (handle.length === 2) { + + const potentialWidth = Math.abs(newWidth); + const potentialHeight = Math.abs(newHeight); + + if (potentialWidth / originalAspectRatio > potentialHeight) { + newHeight = newWidth / originalAspectRatio; + } else { + newWidth = newHeight * originalAspectRatio; + } + } else { + + if (signX !== 0) { + newHeight = newWidth / originalAspectRatio; + } else { + newWidth = newHeight * originalAspectRatio; + } + } + } + + let signX = handle.includes('e') ? 1 : (handle.includes('w') ? -1 : 0); let signY = handle.includes('s') ? 1 : (handle.includes('n') ? -1 : 0);