0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

🐛 Fixes path/curve position for frame

This commit is contained in:
alonso.torres 2021-01-14 11:19:59 +01:00
parent 28658cae73
commit cb7499c10a
4 changed files with 37 additions and 9 deletions

View file

@ -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)))

View file

@ -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

View file

@ -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))))))

View file

@ -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))))))