mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 16:30:37 -05:00
✨ Additional changes to path editing
This commit is contained in:
parent
c7683dfd80
commit
961a7a2e03
9 changed files with 66 additions and 37 deletions
|
@ -38,7 +38,7 @@
|
|||
([v]
|
||||
(cond
|
||||
(point? v)
|
||||
v
|
||||
(Point. (:x v) (:y v))
|
||||
|
||||
(number? v)
|
||||
(point v v)
|
||||
|
|
|
@ -364,7 +364,7 @@
|
|||
(let [edition (get-in state [:workspace-local :edition])
|
||||
drawing (get state :workspace-drawing)]
|
||||
;; Editors handle their own undo's
|
||||
(when-not (or (some? edition) (some? drawing))
|
||||
(when-not (or (some? edition) (not-empty drawing))
|
||||
(let [undo (:workspace-undo state)
|
||||
items (:items undo)
|
||||
index (or (:index undo) (dec (count items)))]
|
||||
|
@ -379,7 +379,7 @@
|
|||
(watch [_ state stream]
|
||||
(let [edition (get-in state [:workspace-local :edition])
|
||||
drawing (get state :workspace-drawing)]
|
||||
(when-not (or (some? edition) (some? drawing))
|
||||
(when-not (or (some? edition) (not-empty drawing))
|
||||
(let [undo (:workspace-undo state)
|
||||
items (:items undo)
|
||||
index (or (:index undo) (dec (count items)))]
|
||||
|
|
|
@ -44,25 +44,30 @@
|
|||
:shapes [shape-id]}]]
|
||||
[rch uch]))
|
||||
|
||||
(defn save-path-content []
|
||||
(ptk/reify ::save-path-content
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [content (get-in state (st/get-path state :content))
|
||||
content (if (= (-> content last :command) :move-to)
|
||||
(into [] (take (dec (count content)) content))
|
||||
content)]
|
||||
(assoc-in state (st/get-path state :content) content)))
|
||||
(defn save-path-content
|
||||
([]
|
||||
(save-path-content {}))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [id (get-in state [:workspace-local :edition])
|
||||
old-content (get-in state [:workspace-local :edit-path id :old-content])]
|
||||
(if (some? old-content)
|
||||
(let [shape (get-in state (st/get-path state))
|
||||
page-id (:current-page-id state)
|
||||
[rch uch] (generate-path-changes page-id shape old-content (:content shape))]
|
||||
(rx/of (dwc/commit-changes rch uch {:commit-local? true})))
|
||||
(rx/empty))))))
|
||||
([{:keys [preserve-move-to] :or {preserve-move-to false}}]
|
||||
(ptk/reify ::save-path-content
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [content (get-in state (st/get-path state :content))
|
||||
content (if (and (not preserve-move-to)
|
||||
(= (-> content last :command) :move-to))
|
||||
(into [] (take (dec (count content)) content))
|
||||
content)]
|
||||
(assoc-in state (st/get-path state :content) content)))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [id (get-in state [:workspace-local :edition])
|
||||
old-content (get-in state [:workspace-local :edit-path id :old-content])]
|
||||
(if (some? old-content)
|
||||
(let [shape (get-in state (st/get-path state))
|
||||
page-id (:current-page-id state)
|
||||
[rch uch] (generate-path-changes page-id shape old-content (:content shape))]
|
||||
(rx/of (dwc/commit-changes rch uch {:commit-local? true})))
|
||||
(rx/empty)))))))
|
||||
|
||||
|
||||
|
|
|
@ -136,8 +136,9 @@
|
|||
handlers (-> (upc/content->handlers content)
|
||||
(get position))
|
||||
|
||||
[idx prefix] (when (= (count handlers) 1) (first handlers))
|
||||
|
||||
[idx prefix] (when (= (count handlers) 1)
|
||||
(first handlers))
|
||||
|
||||
drag-events-stream
|
||||
(->> (streams/position-stream snap-toggled points)
|
||||
(rx/take-until stop-stream)
|
||||
|
|
|
@ -224,9 +224,12 @@
|
|||
(ptk/reify ::create-node-at-position
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [id (st/get-path-id state)]
|
||||
(update-in state (st/get-path state :content) upt/split-segments #{from-p to-p} t)))
|
||||
(let [id (st/get-path-id state)
|
||||
old-content (get-in state (st/get-path state :content))]
|
||||
(-> state
|
||||
(assoc-in [:workspace-local :edit-path id :old-content] old-content)
|
||||
(update-in (st/get-path state :content) upt/split-segments #{from-p to-p} t))))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(rx/of (changes/save-path-content)))))
|
||||
(rx/of (changes/save-path-content {:preserve-move-to true})))))
|
||||
|
|
|
@ -87,7 +87,8 @@
|
|||
(defn next-node
|
||||
"Calculates the next-node to be inserted."
|
||||
[shape position prev-point prev-handler]
|
||||
(let [last-command (-> shape :content last :command)
|
||||
(let [position (select-keys position [:x :y])
|
||||
last-command (-> shape :content last :command)
|
||||
add-line? (and prev-point (not prev-handler) (not= last-command :close-path))
|
||||
add-curve? (and prev-point prev-handler (not= last-command :close-path))]
|
||||
(cond
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
id (get-in state [:workspace-local :edition])
|
||||
content (get-in state (st/get-path state :content))
|
||||
selected-point? #(gsh/has-point-rect? selrect %)
|
||||
|
||||
selected-points (get-in state [:workspace-local :edit-path id :selected-points])
|
||||
|
||||
positions (into (if shift? selected-points #{})
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.data.undo-stack :as u]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.path.state :as st]
|
||||
[app.main.data.workspace.path.changes :as changes]
|
||||
[app.main.store :as store]
|
||||
[beicon.core :as rx]
|
||||
[okulary.core :as l]
|
||||
|
@ -26,20 +27,26 @@
|
|||
(defn- make-entry [state]
|
||||
(let [id (st/get-path-id state)]
|
||||
{:content (get-in state (st/get-path state :content))
|
||||
:selrect (get-in state (st/get-path state :selrect))
|
||||
:points (get-in state (st/get-path state :points))
|
||||
:preview (get-in state [:workspace-local :edit-path id :preview])
|
||||
:last-point (get-in state [:workspace-local :edit-path id :last-point])
|
||||
:prev-handler (get-in state [:workspace-local :edit-path id :prev-handler])}))
|
||||
|
||||
(defn- load-entry [state {:keys [content preview last-point prev-handler]}]
|
||||
(let [id (st/get-path-id state)]
|
||||
(defn- load-entry [state {:keys [content selrect points preview last-point prev-handler]}]
|
||||
(let [id (st/get-path-id state)
|
||||
old-content (get-in state (st/get-path state :content))]
|
||||
(-> state
|
||||
(d/assoc-in-when (st/get-path state :content) content)
|
||||
(d/assoc-in-when (st/get-path state :selrect) selrect)
|
||||
(d/assoc-in-when (st/get-path state :points) points)
|
||||
(d/update-in-when
|
||||
[:workspace-local :edit-path id]
|
||||
assoc
|
||||
:preview preview
|
||||
:last-point last-point
|
||||
:prev-handler prev-handler))))
|
||||
:prev-handler prev-handler
|
||||
:old-content old-content))))
|
||||
|
||||
(defn undo []
|
||||
(ptk/reify ::undo
|
||||
|
@ -54,7 +61,11 @@
|
|||
(-> (load-entry entry)
|
||||
(d/assoc-in-when
|
||||
[:workspace-local :edit-path id :undo-stack]
|
||||
undo-stack)))))))
|
||||
undo-stack)))))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(rx/of (changes/save-path-content)))))
|
||||
|
||||
(defn redo []
|
||||
(ptk/reify ::redo
|
||||
|
@ -68,7 +79,11 @@
|
|||
(load-entry entry)
|
||||
(d/assoc-in-when
|
||||
[:workspace-local :edit-path id :undo-stack]
|
||||
undo-stack))))))
|
||||
undo-stack))))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(rx/of (changes/save-path-content)))))
|
||||
|
||||
(defn add-undo-entry []
|
||||
(ptk/reify ::add-undo-entry
|
||||
|
|
|
@ -165,9 +165,14 @@
|
|||
(point->handlers )
|
||||
(filter (fn [[ci cp]] (and (not= index ci) (not= prefix cp)) )))]
|
||||
|
||||
(when (= (count handlers) 1)
|
||||
(->> handlers
|
||||
first))))
|
||||
(cond
|
||||
(= (count handlers) 1)
|
||||
(->> handlers first)
|
||||
|
||||
(and (= :c1 prefix) (= (count content) index))
|
||||
[(dec index) :c2]
|
||||
|
||||
:else nil)))
|
||||
|
||||
|
||||
(defn get-commands
|
||||
|
|
Loading…
Reference in a new issue