mirror of
https://github.com/penpot/penpot.git
synced 2026-10-02 08:46:15 +00:00
🐛 Fix delete on curve handlers (#11896)
This commit is contained in:
parent
20c818661d
commit
2b8344d3a8
@ -229,20 +229,35 @@
|
|||||||
(update-path-content state (path/toggle-segment-curve content index))
|
(update-path-content state (path/toggle-segment-curve content index))
|
||||||
state)))))
|
state)))))
|
||||||
|
|
||||||
(defn remove-handler
|
(defn remove-handlers
|
||||||
"Collapses one handler onto its node, which becomes independent."
|
"Collapses handlers `[index prefix]` onto their nodes, which become
|
||||||
[index prefix]
|
independent."
|
||||||
(ptk/reify ::remove-handler
|
[handlers]
|
||||||
|
(ptk/reify ::remove-handlers
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [id (st/get-path-id state)
|
(let [id (st/get-path-id state)
|
||||||
content (st/get-path state :content)]
|
content (st/get-path state :content)]
|
||||||
(if (some? content)
|
(if (and (some? content) (seq handlers))
|
||||||
(-> (update-path-content state (path/collapse-handler content index prefix))
|
(let [new-content (reduce (fn [content [index prefix]]
|
||||||
(update-in [:workspace-local :edit-path id :handler-types]
|
(path/collapse-handler content index prefix))
|
||||||
dissoc (helpers/handler-node-index index prefix)))
|
content
|
||||||
|
handlers)
|
||||||
|
nodes (map (fn [[index prefix]]
|
||||||
|
(helpers/handler-node-index index prefix))
|
||||||
|
handlers)]
|
||||||
|
(-> (update-path-content state new-content)
|
||||||
|
(update-in [:workspace-local :edit-path id :handler-types]
|
||||||
|
#(apply dissoc % nodes))
|
||||||
|
(update-in [:workspace-local :edit-path id :selection :handlers]
|
||||||
|
#(reduce disj (or % #{}) handlers))))
|
||||||
state)))))
|
state)))))
|
||||||
|
|
||||||
|
(defn remove-handler
|
||||||
|
"Collapses one handler onto its node, which becomes independent."
|
||||||
|
[index prefix]
|
||||||
|
(remove-handlers #{[index prefix]}))
|
||||||
|
|
||||||
(defn merge-nodes []
|
(defn merge-nodes []
|
||||||
(process-path-tool path/merge-nodes))
|
(process-path-tool path/merge-nodes))
|
||||||
|
|
||||||
@ -287,7 +302,8 @@
|
|||||||
(path/separate-nodes content points offset)))))
|
(path/separate-nodes content points offset)))))
|
||||||
|
|
||||||
(defn delete-selected
|
(defn delete-selected
|
||||||
"Heals selected nodes or opens selected segments."
|
"Heals selected nodes, opens selected segments or collapses selected
|
||||||
|
handlers."
|
||||||
[]
|
[]
|
||||||
(ptk/reify ::delete-selected
|
(ptk/reify ::delete-selected
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
@ -296,17 +312,21 @@
|
|||||||
content (st/get-path state :content)
|
content (st/get-path state :content)
|
||||||
selection (st/get-selection state id)
|
selection (st/get-selection state id)
|
||||||
nodes (get selection :nodes #{})
|
nodes (get selection :nodes #{})
|
||||||
segments (get selection :segments #{})]
|
segments (get selection :segments #{})
|
||||||
|
handlers (get selection :handlers #{})]
|
||||||
(rx/of
|
(rx/of
|
||||||
(cond
|
(cond
|
||||||
;; Node selection takes priority in mixed selections.
|
;; Node selection takes priority in mixed selections.
|
||||||
(seq nodes)
|
(seq nodes)
|
||||||
(process-path-tool (helpers/node-positions content nodes) path/remove-nodes)
|
(process-path-tool (helpers/node-positions content nodes) path/remove-nodes)
|
||||||
|
|
||||||
;; Segment-only selection opens the path.
|
;; Segment selection opens the path.
|
||||||
(seq segments)
|
(seq segments)
|
||||||
(separate-nodes)
|
(separate-nodes)
|
||||||
|
|
||||||
|
(seq handlers)
|
||||||
|
(remove-handlers handlers)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(remove-node)))))))
|
(remove-node)))))))
|
||||||
|
|
||||||
|
|||||||
@ -517,6 +517,35 @@
|
|||||||
(t/is (< (nodes mixed) 4))
|
(t/is (< (nodes mixed) 4))
|
||||||
(t/is (= 1 (move-tos mixed))))))
|
(t/is (= 1 (move-tos mixed))))))
|
||||||
|
|
||||||
|
(t/deftest delete-selected-collapses-selected-handlers
|
||||||
|
(let [id (random-uuid)
|
||||||
|
content (pth/selectable-path-content)
|
||||||
|
run (fn [handlers]
|
||||||
|
(let [state (pth/selectable-path-state
|
||||||
|
id content {:nodes #{} :segments #{} :handlers handlers})
|
||||||
|
events (atom [])]
|
||||||
|
(->> (ptk/watch (path.tools/delete-selected) state nil)
|
||||||
|
(rx/subs! #(swap! events conj %)))
|
||||||
|
(ptk/update (first @events) state)))
|
||||||
|
content-of (fn [st] (vec (get-in st [:workspace-drawing :object :content])))
|
||||||
|
selection-of (fn [st] (get-in st [:workspace-local :edit-path id :selection]))]
|
||||||
|
|
||||||
|
(t/testing "single handler collapses onto its node"
|
||||||
|
(let [state' (run #{[2 :c1]})
|
||||||
|
content' (content-of state')]
|
||||||
|
(t/is (= (gpt/point 10 0) (path/get-handler-point content' 2 :c1)))
|
||||||
|
(t/is (= (gpt/point 18 0) (path/get-handler-point content' 2 :c2)))
|
||||||
|
(t/is (= (gpt/point 8 0) (path/get-handler-point content' 1 :c2)))
|
||||||
|
(t/is (empty? (:handlers (selection-of state'))))))
|
||||||
|
|
||||||
|
(t/testing "multiple handlers collapse and flat curves become lines"
|
||||||
|
(let [state' (run #{[1 :c1] [1 :c2] [2 :c1]})
|
||||||
|
content' (content-of state')]
|
||||||
|
(t/is (= [:move-to :line-to :curve-to] (mapv :command content')))
|
||||||
|
(t/is (= (gpt/point 10 0) (path/get-handler-point content' 2 :c1)))
|
||||||
|
(t/is (= (gpt/point 18 0) (path/get-handler-point content' 2 :c2)))
|
||||||
|
(t/is (empty? (:handlers (selection-of state'))))))))
|
||||||
|
|
||||||
(t/deftest deleting-a-closed-seam-node-heals-its-adjacent-segments
|
(t/deftest deleting-a-closed-seam-node-heals-its-adjacent-segments
|
||||||
(let [id (random-uuid)
|
(let [id (random-uuid)
|
||||||
content (path/content
|
content (path/content
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user