diff --git a/common/app/common/pages/helpers.cljc b/common/app/common/pages/helpers.cljc index f9ce2b24c5..c27f681034 100644 --- a/common/app/common/pages/helpers.cljc +++ b/common/app/common/pages/helpers.cljc @@ -299,7 +299,7 @@ (let [frames (select-frames objects)] (or (->> frames - (d/seek #(gsh/has-point? % position)) + (d/seek #(and position (gsh/has-point? % position))) :id) uuid/zero))) diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 153b51d82c..eddb1e4b22 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -16,6 +16,7 @@ [app.common.spec :as us] [app.common.uuid :as uuid] [app.main.worker :as uw] + [app.main.streams :as ms] [app.util.logging :as log] [app.util.timers :as ts] [beicon.core :as rx] @@ -558,10 +559,12 @@ name (-> objects (retrieve-used-names) (generate-unique-name (:name attrs))) + + position @ms/mouse-position frame-id (if (= :frame (:type attrs)) uuid/zero (or (:frame-id attrs) - (cp/frame-id-by-position objects attrs))) + (cp/frame-id-by-position objects position))) [rchanges uchanges] (add-shape-changes page-id (assoc attrs :id id diff --git a/frontend/src/app/main/data/workspace/drawing/curve.cljs b/frontend/src/app/main/data/workspace/drawing/curve.cljs index 6edb5390d4..a5f028a455 100644 --- a/frontend/src/app/main/data/workspace/drawing/curve.cljs +++ b/frontend/src/app/main/data/workspace/drawing/curve.cljs @@ -16,7 +16,9 @@ [app.common.geom.shapes.path :as gsp] [app.main.streams :as ms] [app.util.geom.path :as path] - [app.main.data.workspace.drawing.common :as common])) + [app.main.data.workspace.drawing.common :as common] + [app.main.data.workspace.common :as dwc] + [app.common.pages :as cp])) (def simplify-tolerance 0.3) @@ -27,7 +29,6 @@ (assoc-in state [:workspace-drawing :object :initialized?] true)) (defn insert-point-segment [state point] - (let [segments (-> state (get-in [:workspace-drawing :object :segments]) (or []) @@ -42,7 +43,17 @@ :selrect selrect :points points)))) +(defn setup-frame-curve [] + (ptk/reify ::setup-frame-path + ptk/UpdateEvent + (update [_ state] + (let [objects (dwc/lookup-page-objects state) + content (get-in state [:workspace-drawing :object :content] []) + position (get-in content [0 :params] nil) + frame-id (cp/frame-id-by-position objects position)] + (-> state + (assoc-in [:workspace-drawing :object :frame-id] frame-id)))))) (defn curve-to-path [{:keys [segments] :as shape}] (let [content (gsp/segments->content segments) @@ -74,5 +85,6 @@ (->> mouse (rx/map (fn [pt] #(insert-point-segment % pt))) (rx/take-until stoper)) - (rx/of finish-drawing-curve + (rx/of (setup-frame-curve) + finish-drawing-curve common/handle-finish-drawing)))))) diff --git a/frontend/src/app/main/data/workspace/drawing/path.cljs b/frontend/src/app/main/data/workspace/drawing/path.cljs index 25515a45c1..a26fde33eb 100644 --- a/frontend/src/app/main/data/workspace/drawing/path.cljs +++ b/frontend/src/app/main/data/workspace/drawing/path.cljs @@ -24,7 +24,8 @@ [app.main.store :as st] [app.main.data.workspace.common :as dwc] [app.main.data.workspace.drawing.common :as common] - [app.common.geom.shapes.path :as gsp])) + [app.common.geom.shapes.path :as gsp] + [app.common.pages :as cp])) ;; SCHEMAS @@ -269,8 +270,7 @@ fix-angle? shift? {:keys [last-point prev-handler]} (get-in state [:workspace-local :edit-path id]) position (cond-> (gpt/point x y) - fix-angle? (position-fixed-angle last-point)) - ] + fix-angle? (position-fixed-angle last-point))] (if-not (= last-point position) (-> state (assoc-in [:workspace-local :edit-path id :last-point] position) @@ -809,6 +809,18 @@ (assoc-in [:workspace-local :edit-path id :selected-handlers] #{}) (assoc-in [:workspace-local :edit-path id :selected-points] #{})))))) +(defn setup-frame-path [] + (ptk/reify ::setup-frame-path + ptk/UpdateEvent + (update [_ state] + + (let [objects (dwc/lookup-page-objects state) + content (get-in state [:workspace-drawing :object :content] []) + position (get-in content [0 :params] nil) + frame-id (cp/frame-id-by-position objects position)] + (-> state + (assoc-in [:workspace-drawing :object :frame-id] frame-id)))))) + (defn handle-new-shape-result [shape-id] (ptk/reify ::handle-new-shape-result ptk/UpdateEvent @@ -821,7 +833,8 @@ ptk/WatchEvent (watch [_ state stream] - (->> (rx/of common/handle-finish-drawing + (->> (rx/of (setup-frame-path) + common/handle-finish-drawing (dwc/start-edition-mode shape-id) (start-path-edit shape-id) (change-edit-mode :draw))))))