feat: cursor alignment when creating generic elements (#5516)

Co-authored-by: Ryan <diweihao@bytedance.com>
This commit is contained in:
Ryan Di 2022-08-01 19:24:46 +08:00 committed by GitHub
parent e7d34677c6
commit 426b5d9537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,12 +108,23 @@ export const dragNewElement = (
if (shouldMaintainAspectRatio) { if (shouldMaintainAspectRatio) {
if (widthAspectRatio) { if (widthAspectRatio) {
height = width / widthAspectRatio; height = width / widthAspectRatio;
} else {
// Depending on where the cursor is at (x, y) relative to where the starting point is
// (originX, originY), we use ONLY width or height to control size increase.
// This allows the cursor to always "stick" to one of the sides of the bounding box.
if (Math.abs(y - originY) > Math.abs(x - originX)) {
({ width, height } = getPerfectElementSize(
elementType,
height,
x < originX ? -width : width,
));
} else { } else {
({ width, height } = getPerfectElementSize( ({ width, height } = getPerfectElementSize(
elementType, elementType,
width, width,
y < originY ? -height : height, y < originY ? -height : height,
)); ));
}
if (height < 0) { if (height < 0) {
height = -height; height = -height;