Selaa lähdekoodia

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

Co-authored-by: Ryan <diweihao@bytedance.com>
Ryan Di 2 vuotta sitten
vanhempi
commit
426b5d9537
1 muutettua tiedostoa jossa 16 lisäystä ja 5 poistoa
  1. 16 5
      src/element/dragElements.ts

+ 16 - 5
src/element/dragElements.ts

@@ -109,11 +109,22 @@ export const dragNewElement = (
     if (widthAspectRatio) {
       height = width / widthAspectRatio;
     } else {
-      ({ width, height } = getPerfectElementSize(
-        elementType,
-        width,
-        y < originY ? -height : height,
-      ));
+      // 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 {
+        ({ width, height } = getPerfectElementSize(
+          elementType,
+          width,
+          y < originY ? -height : height,
+        ));
+      }
 
       if (height < 0) {
         height = -height;