From a99d50abb7461898759aad35b7b01a3b59da1253 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 23 Sep 2022 09:58:42 +0200 Subject: [PATCH] wip #5479 @0.5 --- resources/linkeditor/js/linkeditor.links.js | 4 ++-- resources/linkeditor/js/linkeditor.utils.js | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index fb2b979e6..a8f025521 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -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; } diff --git a/resources/linkeditor/js/linkeditor.utils.js b/resources/linkeditor/js/linkeditor.utils.js index e7f10942f..e2430cc29 100644 --- a/resources/linkeditor/js/linkeditor.utils.js +++ b/resources/linkeditor/js/linkeditor.utils.js @@ -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; -- 2.39.5