From e952d9c70a61919e4d9435548e7c813a9505ab23 Mon Sep 17 00:00:00 2001 From: Luis de Dios Date: Fri, 31 Jul 2026 11:25:20 +0200 Subject: [PATCH] :bug: Fix draw a line/arrow with a single click (#10974) --- .../main/data/workspace/drawing/common.cljs | 42 +++++++++++++++---- .../app/main/data/workspace/drawing/line.cljs | 15 ++++--- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/frontend/src/app/main/data/workspace/drawing/common.cljs b/frontend/src/app/main/data/workspace/drawing/common.cljs index 0356086dd7..10a0164c9c 100644 --- a/frontend/src/app/main/data/workspace/drawing/common.cljs +++ b/frontend/src/app/main/data/workspace/drawing/common.cljs @@ -7,8 +7,11 @@ (ns app.main.data.workspace.drawing.common (:require [app.common.files.helpers :as cfh] + [app.common.geom.point :as gpt] + [app.common.geom.rect :as grc] [app.common.geom.shapes :as gsh] [app.common.types.modifiers :as ctm] + [app.common.types.path :as path] [app.common.types.shape :as cts] [app.main.data.helpers :as dsh] [app.main.data.workspace.shapes :as dwsh] @@ -17,6 +20,31 @@ [beicon.v2.core :as rx] [potok.v2.core :as ptk])) +(defn- click-draw-box + [shape width height] + (-> shape + (assoc :width width) + (assoc :height height) + (assoc :selrect nil) + (assoc :points nil) + (cts/setup-shape) + (gsh/transform-shape (ctm/move-modifiers (- (/ width 2)) (- (/ height 2)))))) + +(defn- click-draw-path + [shape] + (let [start-point (path/get-handler-point (:content shape) 0 nil) + center-x (:x start-point) + center-y (:y start-point) + start (gpt/point (- center-x 50) center-y) + end (gpt/point (+ center-x 50) center-y) + content (path/points->content [start end]) + selrect (path/calc-selrect content)] + (-> shape + (assoc :content content) + (assoc :selrect selrect) + (assoc :points (grc/rect->points selrect)) + (assoc :grow-type :fixed)))) + (defn clear-drawing ([] (clear-drawing nil)) ([{:keys [preserve-tool?]}] @@ -60,15 +88,11 @@ (not click-draw?) (assoc :grow-type :fixed) - (and ^boolean click-draw? (not ^boolean text?)) - (-> (assoc :width width) - (assoc :height height) - ;; NOTE: we need to recalculate the selrect and - ;; points, so we assign `nil` to it - (assoc :selrect nil) - (assoc :points nil) - (cts/setup-shape) - (gsh/transform-shape (ctm/move-modifiers (- (/ width 2)) (- (/ height 2))))) + (and ^boolean click-draw? (not ^boolean text?) (not= :path (:type shape))) + (click-draw-box width height) + + (and ^boolean click-draw? (= :path (:type shape))) + (click-draw-path) (and click-draw? text?) (-> (assoc :height 17 :width 4 :grow-type :auto-width) diff --git a/frontend/src/app/main/data/workspace/drawing/line.cljs b/frontend/src/app/main/data/workspace/drawing/line.cljs index c942a7543c..8b2995fb43 100644 --- a/frontend/src/app/main/data/workspace/drawing/line.cljs +++ b/frontend/src/app/main/data/workspace/drawing/line.cljs @@ -63,7 +63,8 @@ (-> object (assoc :content content) (assoc :selrect selrect) - (assoc :points points'))))))) + (assoc :points points') + (assoc :click-draw? false))))))) (defn- setup-frame [] @@ -101,9 +102,10 @@ (update-in state [:workspace-drawing :object] (fn [{:keys [content selrect] :as shape}] (cond-> shape - (or (empty? content) - (nil? selrect) - (<= (count content) 1)) + (and (not (:click-draw? shape)) + (or (empty? content) + (nil? selrect) + (<= (count content) 1))) (assoc :initialized? false))))))) (defn- arrow-strokes @@ -125,11 +127,13 @@ (let [arrow? (= tool :arrow)] (ptk/reify ::handle-drawing ptk/WatchEvent - (watch [_ _ stream] + (watch [_ state stream] (let [stopper (mse/drag-stopper stream) + zoom (dm/get-in state [:workspace-local :zoom] 1) start @ms/mouse-position shape (cts/setup-shape {:type :path :initialized? true + :click-draw? true :frame-id uuid/zero :parent-id uuid/zero :strokes (arrow-strokes arrow?) @@ -139,6 +143,7 @@ (rx/of #(update % :workspace-drawing assoc :object shape)) (->> ms/mouse-position + (rx/filter #(> (* (gpt/distance % start) zoom) 10)) (rx/with-latest-from ms/mouse-position-shift) (rx/map (fn [[point shift?]] (if shift?