Skip to content

Commit

Permalink
Merge pull request #2 from Print-one/feat/option-to-disable-rotation-…
Browse files Browse the repository at this point in the history
…snap-with-shift

fix(PO-1201): option to hold shift to disable rotation snapping
  • Loading branch information
PaulRill00 authored Dec 5, 2023
2 parents 28452dc + 089d1dc commit 965e22b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/utils/Rotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export default class Rotator {
startPos?: Position;
currentPos?: Position;
docs?: Document[];
keys?: { shift: boolean; ctrl: boolean; alt: boolean };
snapOffset?: number;
snapPoints?: number;
mousePosFetcher?: RotatorOptions['mousePosFetcher'];
Expand Down Expand Up @@ -409,6 +410,11 @@ export default class Rotator {
x: aX - this.center!.x,
y: aY - this.center!.y,
};
this.keys = {
shift: e.shiftKey,
ctrl: e.ctrlKey,
alt: e.altKey,
}

this.rectDim = this.calc(this);
this.updateRect(false);
Expand Down Expand Up @@ -542,8 +548,13 @@ export default class Rotator {

const isWithinSnapRange = Math.abs(angle - closestSnappingPoint) < snappingOffset;

// Enforce rotation snapping (unless shift key is being held)
const shouldSnap = !data.keys!.shift && isWithinSnapRange;

// Override the rotation when the element is supposed to snap
box.r = isWithinSnapRange ? closestSnappingPoint : box.r;
if (shouldSnap) {
box.r = closestSnappingPoint;
}

return box;
}
Expand Down

0 comments on commit 965e22b

Please sign in to comment.