feat: cursor alignment when creating linear elements with shift pressed (#5518)

* feat: cursor alignment when creating linear elements

* feat: apply cursor alignment to multi-point linear elements

* refactor: rename size helper function
This commit is contained in:
Ryan Di 2022-08-02 18:13:19 +08:00 committed by GitHub
parent 54c7ec416a
commit 865d29388c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 9 deletions

View file

@ -87,9 +87,9 @@ import {
getDragOffsetXY,
getElementWithTransformHandleType,
getNormalizedDimensions,
getPerfectElementSize,
getResizeArrowDirection,
getResizeOffsetXY,
getLockedLinearCursorAlignSize,
getTransformHandleTypeFromCoords,
hitTest,
isHittingElementBoundingBoxWithoutHittingElement,
@ -2768,10 +2768,13 @@ class App extends React.Component<AppProps, AppState> {
if (shouldRotateWithDiscreteAngle(event)) {
({ width: dxFromLastCommitted, height: dyFromLastCommitted } =
getPerfectElementSize(
this.state.activeTool.type,
dxFromLastCommitted,
dyFromLastCommitted,
getLockedLinearCursorAlignSize(
// actual coordinate of the last committed point
lastCommittedX + rx,
lastCommittedY + ry,
// cursor-grid coordinate
gridX,
gridY,
));
}
@ -4241,10 +4244,11 @@ class App extends React.Component<AppProps, AppState> {
let dy = gridY - draggingElement.y;
if (shouldRotateWithDiscreteAngle(event) && points.length === 2) {
({ width: dx, height: dy } = getPerfectElementSize(
this.state.activeTool.type,
dx,
dy,
({ width: dx, height: dy } = getLockedLinearCursorAlignSize(
draggingElement.x,
draggingElement.y,
pointerCoords.x,
pointerCoords.y,
));
}