]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5751 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 Feb 2023 15:26:44 +0000 (16:26 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 Feb 2023 15:26:44 +0000 (16:26 +0100)
resources/linkeditor/js/linkeditor.links.js

index 9c59fef3193263b01cf0a6ef38d24fd59b3a2827..d018d33ce1d63c1519a1ef9784ffc2ccadeb470a 100644 (file)
@@ -52,7 +52,6 @@ LinkeditorLinks.prototype = {
                     selectLink = false;
                 } else {
                     selectLink = true;
-                    deselectAll = true;
                 }
             }
             if (deselectAll) {
@@ -606,22 +605,39 @@ LinkeditorLinks.prototype = {
             return;
         }
 
-        let magnet = !key.ctrl && $(".link.selected").length === 1;
+        let magnet = !key.ctrl;
         let $this = this;
         let f = 1 / (this.linkeditor.fs * this.linkeditor.zoom.zoom);
         let dx = (this.linkeditor.mx - this.dragLinkPos.x) * f;
         let dy = (this.linkeditor.my - this.dragLinkPos.y) * f;
 
+        var rect = {left: 10000000, top: 10000000, right: 0, bottom: 0};
+
+        if (magnet) {
+            $(".link.selected").each(function () {
+                let left = $(this).data('drag-orig-left') + dx;
+                let top = $(this).data('drag-orig-top') + dy;
+                let right = left + $(this).data('drag-orig-width');
+                let bottom = top + $(this).data('drag-orig-height');
+
+                rect.left = Math.min(left, rect.left);
+                rect.right = Math.max(right, rect.right);
+                rect.top = Math.min(top, rect.top);
+                rect.bottom = Math.max(bottom, rect.bottom);
+            });
+
+            let rx = $this.linkeditor.utils.magnetize(rect.left, $this.magnetValuesX, rect.right - rect.left)
+            let ry = $this.linkeditor.utils.magnetize(rect.top, $this.magnetValuesY, rect.bottom - rect.top);
+
+            dx -= rect.left - rx;
+            dy -= rect.top - ry;
+        }
+
+
         $(".link.selected").each(function () {
             let left = $(this).data('drag-orig-left') + dx;
             let top = $(this).data('drag-orig-top') + dy;
 
-            // Magnets are enabled when ctrl is not pressed and there is only one item in the selection
-            if (magnet) {
-                left = $this.linkeditor.utils.magnetize(left, $this.magnetValuesX, $(this).data('drag-orig-width'));
-                top = $this.linkeditor.utils.magnetize(top, $this.magnetValuesY, $(this).data('drag-orig-height'));
-            }
-
             $(this)
                 .attr('fb-left', left)
                 .attr('fb-top', top)