mirror of
https://github.com/penpot/penpot.git
synced 2025-01-26 08:29:42 -05:00
🐛 Fix problem when deleting all nodes from a path
This commit is contained in:
parent
57b6807333
commit
5352918ff8
3 changed files with 60 additions and 29 deletions
|
@ -6,42 +6,67 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.path.changes
|
(ns app.main.data.workspace.path.changes
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.pages :as cp]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
[app.main.data.workspace.path.helpers :as helpers]
|
[app.main.data.workspace.path.helpers :as helpers]
|
||||||
[app.main.data.workspace.path.spec :as spec]
|
[app.main.data.workspace.path.spec :as spec]
|
||||||
[app.main.data.workspace.path.state :as st]
|
[app.main.data.workspace.path.state :as st]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
(defn generate-path-changes
|
(defn generate-path-changes
|
||||||
"Generates content changes and the undos for the content given"
|
"Generates content changes and the undos for the content given"
|
||||||
[page-id shape old-content new-content]
|
[objects page-id shape old-content new-content]
|
||||||
(us/verify ::spec/content old-content)
|
(us/verify ::spec/content old-content)
|
||||||
(us/verify ::spec/content new-content)
|
(us/verify ::spec/content new-content)
|
||||||
(let [shape-id (:id shape)
|
(let [shape-id (:id shape)
|
||||||
|
frame-id (:frame-id shape)
|
||||||
|
parent-id (:parent-id shape)
|
||||||
|
parent-index (cp/position-on-parent shape-id objects)
|
||||||
|
|
||||||
[old-points old-selrect] (helpers/content->points+selrect shape old-content)
|
[old-points old-selrect] (helpers/content->points+selrect shape old-content)
|
||||||
[new-points new-selrect] (helpers/content->points+selrect shape new-content)
|
[new-points new-selrect] (helpers/content->points+selrect shape new-content)
|
||||||
|
|
||||||
rch [{:type :mod-obj
|
rch (if (empty? new-content)
|
||||||
:id shape-id
|
[{:type :del-obj
|
||||||
:page-id page-id
|
:id shape-id
|
||||||
:operations [{:type :set :attr :content :val new-content}
|
:page-id page-id}
|
||||||
{:type :set :attr :selrect :val new-selrect}
|
{:type :reg-objects
|
||||||
{:type :set :attr :points :val new-points}]}
|
:page-id page-id
|
||||||
{:type :reg-objects
|
:shapes [shape-id]}]
|
||||||
:page-id page-id
|
|
||||||
:shapes [shape-id]}]
|
|
||||||
|
|
||||||
uch [{:type :mod-obj
|
[{:type :mod-obj
|
||||||
:id shape-id
|
:id shape-id
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:operations [{:type :set :attr :content :val old-content}
|
:operations [{:type :set :attr :content :val new-content}
|
||||||
{:type :set :attr :selrect :val old-selrect}
|
{:type :set :attr :selrect :val new-selrect}
|
||||||
{:type :set :attr :points :val old-points}]}
|
{:type :set :attr :points :val new-points}]}
|
||||||
{:type :reg-objects
|
{:type :reg-objects
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:shapes [shape-id]}]]
|
:shapes [shape-id]}])
|
||||||
|
|
||||||
|
uch (if (empty? new-content)
|
||||||
|
[{:type :add-obj
|
||||||
|
:id shape-id
|
||||||
|
:obj shape
|
||||||
|
:page-id page-id
|
||||||
|
:frame-id frame-id
|
||||||
|
:parent-id parent-id
|
||||||
|
:index parent-index}
|
||||||
|
{:type :reg-objects
|
||||||
|
:page-id page-id
|
||||||
|
:shapes [shape-id]}]
|
||||||
|
[{:type :mod-obj
|
||||||
|
:id shape-id
|
||||||
|
:page-id page-id
|
||||||
|
:operations [{:type :set :attr :content :val old-content}
|
||||||
|
{:type :set :attr :selrect :val old-selrect}
|
||||||
|
{:type :set :attr :points :val old-points}]}
|
||||||
|
{:type :reg-objects
|
||||||
|
:page-id page-id
|
||||||
|
:shapes [shape-id]}])]
|
||||||
[rch uch]))
|
[rch uch]))
|
||||||
|
|
||||||
(defn save-path-content
|
(defn save-path-content
|
||||||
|
@ -61,12 +86,13 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [id (get-in state [:workspace-local :edition])
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
|
id (get-in state [:workspace-local :edition])
|
||||||
old-content (get-in state [:workspace-local :edit-path id :old-content])]
|
old-content (get-in state [:workspace-local :edit-path id :old-content])]
|
||||||
(if (some? old-content)
|
(if (some? old-content)
|
||||||
(let [shape (get-in state (st/get-path state))
|
(let [shape (get-in state (st/get-path state))
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
[rch uch] (generate-path-changes page-id shape old-content (:content shape))]
|
[rch uch] (generate-path-changes objects page-id shape old-content (:content shape))]
|
||||||
(rx/of (dch/commit-changes rch uch {:commit-local? true})))
|
(rx/of (dch/commit-changes rch uch {:commit-local? true})))
|
||||||
(rx/empty)))))))
|
(rx/empty)))))))
|
||||||
|
|
||||||
|
|
|
@ -12,17 +12,18 @@
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
[app.main.data.workspace.path.changes :as changes]
|
[app.main.data.workspace.path.changes :as changes]
|
||||||
[app.main.data.workspace.path.common :as common]
|
[app.main.data.workspace.path.common :as common]
|
||||||
|
[app.main.data.workspace.path.drawing :as drawing]
|
||||||
[app.main.data.workspace.path.helpers :as helpers]
|
[app.main.data.workspace.path.helpers :as helpers]
|
||||||
[app.main.data.workspace.path.selection :as selection]
|
[app.main.data.workspace.path.selection :as selection]
|
||||||
[app.main.data.workspace.path.state :as st]
|
[app.main.data.workspace.path.state :as st]
|
||||||
[app.main.data.workspace.path.streams :as streams]
|
[app.main.data.workspace.path.streams :as streams]
|
||||||
[app.main.data.workspace.path.drawing :as drawing]
|
|
||||||
[app.main.data.workspace.path.undo :as undo]
|
[app.main.data.workspace.path.undo :as undo]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.util.path.commands :as upc]
|
[app.util.path.commands :as upc]
|
||||||
[app.util.path.geom :as upg]
|
[app.util.path.geom :as upg]
|
||||||
[app.util.path.tools :as upt]
|
|
||||||
[app.util.path.subpaths :as ups]
|
[app.util.path.subpaths :as ups]
|
||||||
|
[app.util.path.tools :as upt]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
|
@ -46,7 +47,9 @@
|
||||||
(ptk/reify ::apply-content-modifiers
|
(ptk/reify ::apply-content-modifiers
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [id (st/get-path-id state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
|
|
||||||
|
id (st/get-path-id state)
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
shape (get-in state (st/get-path state))
|
shape (get-in state (st/get-path state))
|
||||||
content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers])
|
content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers])
|
||||||
|
@ -58,7 +61,7 @@
|
||||||
new-points (->> new-content upg/content->points)
|
new-points (->> new-content upg/content->points)
|
||||||
point-change (->> (map hash-map old-points new-points) (reduce merge))
|
point-change (->> (map hash-map old-points new-points) (reduce merge))
|
||||||
|
|
||||||
[rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)]
|
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]
|
||||||
|
|
||||||
(rx/of (dch/commit-changes rch uch {:commit-local? true})
|
(rx/of (dch/commit-changes rch uch {:commit-local? true})
|
||||||
(selection/update-selection point-change)
|
(selection/update-selection point-change)
|
||||||
|
|
|
@ -6,13 +6,14 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.path.tools
|
(ns app.main.data.workspace.path.tools
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.geom.point :as gpt]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
[app.main.data.workspace.path.changes :as changes]
|
[app.main.data.workspace.path.changes :as changes]
|
||||||
[app.main.data.workspace.path.common :as common]
|
[app.main.data.workspace.path.common :as common]
|
||||||
[app.main.data.workspace.path.state :as st]
|
[app.main.data.workspace.path.state :as st]
|
||||||
[app.util.path.tools :as upt]
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.util.path.subpaths :as ups]
|
[app.util.path.subpaths :as ups]
|
||||||
[app.common.geom.point :as gpt]
|
[app.util.path.tools :as upt]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
|
@ -24,14 +25,15 @@
|
||||||
(ptk/reify ::process-path-tool
|
(ptk/reify ::process-path-tool
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [id (st/get-path-id state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
|
id (st/get-path-id state)
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
shape (get-in state (st/get-path state))
|
shape (get-in state (st/get-path state))
|
||||||
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
|
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
|
||||||
points (or points selected-points)
|
points (or points selected-points)
|
||||||
new-content (-> (tool-fn (:content shape) points)
|
new-content (-> (tool-fn (:content shape) points)
|
||||||
(ups/close-subpaths))
|
(ups/close-subpaths))
|
||||||
[rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)]
|
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]
|
||||||
(rx/of (dch/commit-changes rch uch {:commit-local? true})))))))
|
(rx/of (dch/commit-changes rch uch {:commit-local? true})))))))
|
||||||
|
|
||||||
(defn make-corner
|
(defn make-corner
|
||||||
|
|
Loading…
Add table
Reference in a new issue