From 27010ae0fb308d790ba66981049834e0aaadc5ab Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 9 Apr 2024 12:03:59 +0200 Subject: [PATCH] :bug: Fix problem when moving horizontal/vertical lines --- .../main/ui/workspace/viewport/selection.cljs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/viewport/selection.cljs b/frontend/src/app/main/ui/workspace/viewport/selection.cljs index 8d04c1ac2..5789e2ff1 100644 --- a/frontend/src/app/main/ui/workspace/viewport/selection.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/selection.cljs @@ -36,6 +36,8 @@ (def selection-rect-width 1) (def min-selrect-side 10) (def small-selrect-side 30) +(def min-selrect-width 10) +(def min-selrect-height 10) (mf/defc selection-rect {::mf/wrap-props false} @@ -43,12 +45,27 @@ (let [x (dm/get-prop rect :x) y (dm/get-prop rect :y) width (dm/get-prop rect :width) - height (dm/get-prop rect :height)] + height (dm/get-prop rect :height) + + ;; This is a calculation to create a "minimum" interactable rect + ;; Is necesary so that small shapes in x/y (like lines) can be moved + ;; better + [x width] + (if (< width (/ min-selrect-width zoom)) + (let [width' (/ min-selrect-width zoom)] + [(- x (/ (- width' width) 2)) width']) + [x width]) + + [y height] + (if (< height (/ min-selrect-height zoom)) + (let [height' (/ min-selrect-height zoom)] + [(- y (/ (- height' height) 2)) height']) + [y height])] [:rect.main.viewport-selrect {:x x :y y - :width width - :height height + :width (max width (/ 10 zoom)) + :height (max height (/ 10 zoom)) :transform (str transform) :on-pointer-down on-move-selected :on-context-menu on-context-menu