]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5479 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Sep 2022 07:58:42 +0000 (09:58 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Sep 2022 07:58:42 +0000 (09:58 +0200)
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/js/linkeditor.utils.js

index fb2b979e6ef9ff6cc6ddba0f92c7b45022bbae3c..a8f02552139994c9df3cd5c9a41a3536d1d227af 100644 (file)
@@ -164,12 +164,12 @@ LinkeditorLinks.prototype = {
                     newHeight += diff;
                 }
                 if (width !== 0) {
-                    let magnetLeft = $this.linkeditor.utils.magnetize(newLeft, $this.magnetValuesX, newWidth);
+                    let magnetLeft = $this.linkeditor.utils.magnetize(newLeft, $this.magnetValuesX, newWidth, true);
                     diff = newLeft - magnetLeft;
                     newWidth -= diff;
                 }
                 if (height !== 0) {
-                    let magnetTop = $this.linkeditor.utils.magnetize(newTop, $this.magnetValuesY, newHeight);
+                    let magnetTop = $this.linkeditor.utils.magnetize(newTop, $this.magnetValuesY, newHeight, true);
                     diff = newTop - magnetTop;
                     newHeight -= diff;
                 }
index e7f10942ff6c532f06548d2a00ed959f4f2e2a00..e2430cc292c4d41ffc3060a2cabd6f788345f2e0 100644 (file)
@@ -44,7 +44,10 @@ LinkeditorUtils.prototype = {
         return result;
     },
 
-    magnetize: function (value, values, width) {
+    magnetize: function (value, values, width, onlyCheckOtherSide) {
+        if (onlyCheckOtherSide === undefined) {
+            onlyCheckOtherSide = false;
+        }
         if (width === undefined) {
             width = 0;
         }
@@ -59,13 +62,17 @@ LinkeditorUtils.prototype = {
 
         for (let i in values) {
             let v = values[i];
-            let diff = Math.abs(v - value);
-            let diffOtherSide = Math.abs(v - (value + width));
-            if (diff < min) {
-                min = diff;
-                magnetValue = v;
-                magnetizeOtherSide = false;
+
+            if (!onlyCheckOtherSide) {
+                let diff = Math.abs(v - value);
+                if (diff < min) {
+                    min = diff;
+                    magnetValue = v;
+                    magnetizeOtherSide = false;
+                }
             }
+
+            let diffOtherSide = Math.abs(v - (value + width));
             if (diffOtherSide < min) {
                 min = diffOtherSide;
                 magnetValue = v;