0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 16:00:19 -05:00

🐛 Fix ungroup a component leaves asterisk in layers

This commit is contained in:
Andrés Moya 2022-02-01 13:59:32 +01:00 committed by Andrey Antukh
parent 75930a0ce9
commit 449756a0e4
3 changed files with 58 additions and 56 deletions

View file

@ -76,6 +76,7 @@
- Normalize zoom levels in workspace and viewer [Taiga #2631](https://tree.taiga.io/project/penpot/issue/2631) - Normalize zoom levels in workspace and viewer [Taiga #2631](https://tree.taiga.io/project/penpot/issue/2631)
- Avoid empty names in projects, files and pages [Taiga #2594](https://tree.taiga.io/project/penpot/issue/2594) - Avoid empty names in projects, files and pages [Taiga #2594](https://tree.taiga.io/project/penpot/issue/2594)
- Fix "move to" menu when duplicated team or project names [Taiga #2655](https://tree.taiga.io/project/penpot/issue/2655) - Fix "move to" menu when duplicated team or project names [Taiga #2655](https://tree.taiga.io/project/penpot/issue/2655)
- Fix ungroup a component leaves an asterisk in layers [Taiga #2694](https://tree.taiga.io/project/penpot/issue/2694)
### :arrow_up: Deps updates ### :arrow_up: Deps updates

View file

@ -47,29 +47,33 @@
(update :undo-changes d/preconj del-change))))) (update :undo-changes d/preconj del-change)))))
(defn change-parent (defn change-parent
[changes parent-id shapes] ([changes parent-id shapes] (change-parent changes parent-id shapes nil))
(assert (contains? (meta changes) ::objects) "Call (with-objects) first to use this function") ([changes parent-id shapes index]
(assert (contains? (meta changes) ::objects) "Call (with-objects) first to use this function")
(let [objects (::objects (meta changes)) (let [objects (::objects (meta changes))
set-parent-change set-parent-change
{:type :mov-objects (cond-> {:type :mov-objects
:parent-id parent-id :parent-id parent-id
:page-id (::page-id (meta changes)) :page-id (::page-id (meta changes))
:shapes (->> shapes (mapv :id))} :shapes (->> shapes (mapv :id))}
mk-undo-change (some? index)
(fn [change-set shape] (assoc :index index))
(d/preconj
change-set
{:type :mov-objects
:page-id (::page-id (meta changes))
:parent-id (:parent-id shape)
:shapes [(:id shape)]
:index (cp/position-on-parent (:id shape) objects)}))]
(-> changes mk-undo-change
(update :redo-changes conj set-parent-change) (fn [change-set shape]
(update :undo-changes #(reduce mk-undo-change % shapes))))) (d/preconj
change-set
{:type :mov-objects
:page-id (::page-id (meta changes))
:parent-id (:parent-id shape)
:shapes [(:id shape)]
:index (cp/position-on-parent (:id shape) objects)}))]
(-> changes
(update :redo-changes conj set-parent-change)
(update :undo-changes #(reduce mk-undo-change % shapes))))))
(defn- generate-operation (defn- generate-operation
"Given an object old and new versions and an attribute will append into changes "Given an object old and new versions and an attribute will append into changes

View file

@ -9,6 +9,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.changes-builder :as cb]
[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.common :as dwc] [app.main.data.workspace.common :as dwc]
@ -136,8 +137,8 @@
[group rchanges uchanges])) [group rchanges uchanges]))
(defn prepare-remove-group (defn prepare-remove-group
[page-id group objects] [it page-id group objects]
(let [shapes (into [] (:shapes group)) ; ensure we always have vector (let [children (mapv #(get objects %) (:shapes group))
parent-id (cp/get-parent (:id group) objects) parent-id (cp/get-parent (:id group) objects)
parent (get objects parent-id) parent (get objects parent-id)
@ -147,29 +148,25 @@
(filter #(#{(:id group)} (second %))) (filter #(#{(:id group)} (second %)))
(ffirst)) (ffirst))
rchanges [{:type :mov-objects ids-to-detach (when (:component-id group)
:page-id page-id (cp/get-children (:id group) objects))
:parent-id parent-id
:shapes shapes detach-fn (fn [attrs]
:index index-in-parent} (dissoc attrs
{:type :del-obj :component-id
:page-id page-id :component-file
:id (:id group)}] :component-root?
uchanges [{:type :add-obj :remote-synced?
:page-id page-id :shape-ref
:id (:id group) :touched))]
:frame-id (:frame-id group)
:obj (assoc group :shapes [])} (cond-> (-> (cb/empty-changes it page-id)
{:type :mov-objects (cb/with-objects objects)
:page-id page-id (cb/change-parent parent-id children index-in-parent)
:parent-id (:id group) (cb/remove-objects [(:id group)]))
:shapes shapes}
{:type :mov-objects (some? ids-to-detach)
:page-id page-id (cb/update-shapes ids-to-detach detach-fn))))
:parent-id parent-id
:shapes [(:id group)]
:index index-in-parent}]]
[rchanges uchanges]))
(defn prepare-remove-mask (defn prepare-remove-mask
[page-id mask] [page-id mask]
@ -223,20 +220,20 @@
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
is-group? #(or (= :bool (:type %)) (= :group (:type %))) is-group? #(or (= :bool (:type %)) (= :group (:type %)))
lookup #(get objects %) lookup #(get objects %)
prepare #(prepare-remove-group page-id % objects) prepare #(prepare-remove-group it page-id % objects)
changes (sequence changes-list (sequence
(comp (map lookup) (comp (map lookup)
(filter is-group?) (filter is-group?)
(map prepare)) (map prepare))
(wsh/lookup-selected state)) (wsh/lookup-selected state))
rchanges (into [] (mapcat first) changes) changes {:redo-changes (vec (mapcat :redo-changes changes-list))
uchanges (into [] (mapcat second) changes)] :undo-changes (vec (mapcat :undo-changes changes-list))
:origin it}]
(rx/of (dch/commit-changes changes))))))
(rx/of (dch/commit-changes {:redo-changes rchanges
:undo-changes uchanges
:origin it}))))))
(def mask-group (def mask-group
(ptk/reify ::mask-group (ptk/reify ::mask-group
ptk/WatchEvent ptk/WatchEvent