feat: cursor alignment when creating generic elements (#5516)
Co-authored-by: Ryan <diweihao@bytedance.com>
This commit is contained in:
parent
e7d34677c6
commit
426b5d9537
@ -109,11 +109,22 @@ export const dragNewElement = (
|
|||||||
if (widthAspectRatio) {
|
if (widthAspectRatio) {
|
||||||
height = width / widthAspectRatio;
|
height = width / widthAspectRatio;
|
||||||
} else {
|
} else {
|
||||||
({ width, height } = getPerfectElementSize(
|
// Depending on where the cursor is at (x, y) relative to where the starting point is
|
||||||
elementType,
|
// (originX, originY), we use ONLY width or height to control size increase.
|
||||||
width,
|
// This allows the cursor to always "stick" to one of the sides of the bounding box.
|
||||||
y < originY ? -height : height,
|
if (Math.abs(y - originY) > Math.abs(x - originX)) {
|
||||||
));
|
({ width, height } = getPerfectElementSize(
|
||||||
|
elementType,
|
||||||
|
height,
|
||||||
|
x < originX ? -width : width,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
({ width, height } = getPerfectElementSize(
|
||||||
|
elementType,
|
||||||
|
width,
|
||||||
|
y < originY ? -height : height,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if (height < 0) {
|
if (height < 0) {
|
||||||
height = -height;
|
height = -height;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user