Keep Proportion with shift

This commit is contained in:
Dariusz L
2025-06-21 00:25:09 +02:00
parent 8cd0716449
commit d9ac5546dd

View File

@@ -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);