From ad787f9994c0061cec240e7c30cf4630cf3fdb8f Mon Sep 17 00:00:00 2001 From: MissLixf <1090474924@qq.com> Date: Thu, 18 Apr 2024 10:42:11 +0800 Subject: [PATCH] feat(rotate): support snap angle when rotate with hotkey #WIK-15113 --- .changeset/breezy-knives-tie.md | 4 ++-- packages/common/src/types/rotate.ts | 1 - packages/draw/src/plugins/with-draw-rotate.ts | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.changeset/breezy-knives-tie.md b/.changeset/breezy-knives-tie.md index ab75f5968..a91623fd0 100644 --- a/.changeset/breezy-knives-tie.md +++ b/.changeset/breezy-knives-tie.md @@ -1,5 +1,5 @@ --- -'@plait/draw': patch +'@plait/draw': minor --- -fix(draw): support snap angle when rotate with hotkey +feat(rotate): support snap angle when rotate with hotkey diff --git a/packages/common/src/types/rotate.ts b/packages/common/src/types/rotate.ts index 4581fcc2f..4a498b9b8 100644 --- a/packages/common/src/types/rotate.ts +++ b/packages/common/src/types/rotate.ts @@ -4,5 +4,4 @@ export interface RotateRef { elements: T[]; startPoint: Point; angle?: number; - isShift?: boolean; } diff --git a/packages/draw/src/plugins/with-draw-rotate.ts b/packages/draw/src/plugins/with-draw-rotate.ts index 612c55ba5..b05120f81 100644 --- a/packages/draw/src/plugins/with-draw-rotate.ts +++ b/packages/draw/src/plugins/with-draw-rotate.ts @@ -63,7 +63,7 @@ export const withDrawRotate = (board: PlaitBoard) => { board.pointerMove = (event: PointerEvent) => { if (rotateRef) { event.preventDefault(); - rotateRef.isShift = !!event.shiftKey; + const isShift = !!event.shiftKey; addRotating(board, rotateRef); const endPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y)); const selectionRectangle = getRectangleByElements(board, rotateRef.elements, false); @@ -75,7 +75,7 @@ export const withDrawRotate = (board: PlaitBoard) => { throttleRAF(board, 'with-common-rotate', () => { if (rotateRef && rotateRef.startPoint) { let angle = getAngleBetweenPoints(rotateRef.startPoint, endPoint, selectionCenterPoint); - if (rotateRef.isShift) { + if (isShift) { angle += Math.PI / 12 / 2; angle -= angle % (Math.PI / 12); }